Skip to content

Conditional Routing #1143

@jkassis

Description

@jkassis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions