draco icon indicating copy to clipboard operation
draco copied to clipboard

Implement Router URL parsing API like how `warp` does

Open utkarshkukreti opened this issue 5 years ago • 1 comments

The current parsing API is clunky: the parts which don't have a meaningful return value (which return ()) are sent to the map function:

.alt(("posts", query("sort").optional()), |((), sort)| {
    Route::PostIndex { sort }
})

Warp uses some type system magic to flatten the arguments and filter out the ones which return ():

let hi = warp::path("hello")
    .and(warp::path::param())
    .and(warp::header("user-agent"))
    .map(|param: String, agent: String| {
        format!("Hello {}, whose agent is {}", param, agent)
    });

https://docs.rs/warp/0.1.9/warp/index.html

utkarshkukreti avatar Nov 08 '18 08:11 utkarshkukreti