我想要一个带有 Rust warp 的分层路由结构,如下所示:
/
/api
/api/public
/api/public/articles
/api/admin
/api/admin/articles
我想像下面的代码一样定义我的路由范围,当然这不起作用:
// *** Again: this code does NOT work.
// *** I've put it here simply for demonstration purposes
pub fn get_routes() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
let articles = warp::path("articles")
.map(|| "articles index");
let public = warp::path("public")
.and(warp::path::end())
.map(|| "public index")
.or(articles);
let admin = warp::path("admin")
.and(warp::path::end())
.map(|| "admin index")
.or(articles);
let api = warp::path("api")
.and(warp::path::end())
.map(|| "api index")
.or(admin);
let root_index = warp::path::end()
.map(|| "root index")
.or(api);
root_index
}
有什么办法可以实现捎带路线,即带有锈经的范围?