guide on Rocket's site表明可以对动态路线进行排名。该示例使用动态部分的不同类型作为路由的匹配条件。当我使用除usize
以外的任何其他网址时,我收到以下错误:
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();
}
我希望在404 error
显示测试/user/three
而不是last rank
页面。为什么不这样做?
答案 0 :(得分:2)
Rocket不知道您的路线,除非您告诉它们:
fn main() {
rocket::ignite().mount("/", routes![user, user_int, user_str]).launch();
// ^^^^^^^^^^^^^^^^^^^^
}