【发布时间】:2018-03-11 10:37:37
【问题描述】:
guide on Rocket's site 表示可以对动态路由进行排名。该示例使用不同类型的动态部分作为路由的匹配条件。当我输入一个包含 usize 以外的任何内容的 url 时,我收到以下错误:
GET /user/three text/html:
=> Matched: GET /user/<id>
=> Failed to parse 'id': RawStr("three")
=> Outcome: Forward
=> Error: No matching routes for GET /user/three text/html.
=> Warning: Responding with 404 Not Found catcher.
=> Response succeeded.
我正在使用的代码:
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
use rocket::http::RawStr;
#[get("/user/<id>")]
fn user(id: usize) -> String { format!("First rank") }
#[get("/user/<id>", rank = 2)]
fn user_int(id: isize) -> String { format!("second rank") }
#[get("/user/<id>", rank = 3)]
fn user_str(id: &RawStr) -> String { format!("last rank") }
fn main() {
rocket::ignite().mount("/", routes![user]).launch();
}
我希望/user/three 的页面显示测试last rank 而不是404 error。为什么不这样做?
【问题讨论】:
标签: rust rust-rocket