Rocket 未在 URL 中解析 RawStr 以匹配路由

Rocket not parsing RawStr in a URL to match route

guide on Rocket's site表示可以对动态路由进行排序。该示例使用不同类型的动态部分作为路由的匹配条件。当我将 url 与 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();
}

我希望 /user/three 的页面显示测试 last rank 而不是 404 error。为什么不这样做?

Rocket 不知道你的路线除非你告诉它:

fn main() {
    rocket::ignite().mount("/", routes![user, user_int, user_str]).launch();
    //                                      ^^^^^^^^^^^^^^^^^^^^
}