It might be that there's a way to do this by composing filters, but it seems to escape me for the moment.
If I have a route of /:something, is there a way to provide a pattern to filter? For example, say I wanted to accept /:something, but only where :something is value1 or value2. It seems I could maybe join some handlers up together to make this happen, but not in a way that would provide access to the value of :something?
You could make a stronger type than a generic regex, by using warp::path::param::<T>(). For example:
struct Something;
impl FromStr for Something {
type Err = ();
fn from_str(s: &str) -> Result<Something, ()> {
match s {
"value1" | "value2" => Ok(Something),
_ => Err(())
}
}
}
let something = warp::path::param::<Something>();
@seanmonstar interesting, so an error will just 404 the request?
Yep!
Most helpful comment
You could make a stronger type than a generic regex, by using
warp::path::param::<T>(). For example: