I am starting with Rust, and maybe I am trying to solve this in a wrong way, but I can't figure out how to dynamically compose multiple Warp filters into a single one.
Example:
// These could come from some command line args or maybe a config file
let apps = vec!["app1", "app2", "app3"];
let routes = apps
.into_iter()
.map(|app| {
warp::get()
.and(warp::path("apps"))
.and(warp::path(app))
.map(warp::reply)
})
.fold(warp::any(), |routes, route| routes.or(route));
warp::serve(routes)
.run(([127, 0, 0, 1], 3000))
.await;
I can't make .fold to type check. Am I trying something absurd here?
The type produced by routes.or(route) recursively contains the types of routes and route, meaning it will be different for every route appended. You should be able to box the filters to make them all the same type: