Conditional Routing
Author: jkassisCreated Oct 17, 2025Updated Oct 17, 2025
Labelsfeature
Is your feature request related to a problem? Please describe.
I'm always frustrated when trying to write a conditional chain of filters using or.
Describe the solution you'd like from the examples, we have this...
pub fn assets_filter() -> BoxedFilter<(impl Reply,)> {
warp::path("assets")
.and(warp::fs::dir("./assets"))
.boxed()
}I'd like the ability to do something like this...
pub fn assets_filter() -> BoxedFilter<(impl Reply,)> {
if let Some(optional_filter) = optional_filter {
warp::path("assets")
.and(warp::fs::dir("./assets"))
.or(optional_filter)
.boxed()
} else {
warp::path("assets").and(warp::fs::dir("./assets")).boxed()
}
}Describe alternatives you've considered I've tried just about everything to make types work out. While it's ok to return BoxedFilter<(impl Reply,)>, it's not OK to return two different variants of this from the fn body.
Additional context
This was raised and closed in https://github.com/seanmonstar/warp/issues/699, but does not seem like a solution for the rest of us.
Source: seanmonstar/warp