你如何改变Rocket网站上的例子来取一个日期而不是一个年龄/ u8
?
网站上的例子:
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
#[get("/hello/<name>/<age>")]
fn hello(name: String, age: u8) -> String {
format!("Hello, {} year old named {}!", age, name)
}
fn main() {
rocket::ignite().mount("/", routes![hello]).launch();
}
我想要或多或少相同的输出(你好,58岁,名叫约翰!),但有类似的东西
#[get("/hello/<name>/<birthdate>")]
而不是那个
#[get("/hello/<name>/<age>")]
我认为正确的结构是chrono::DateTime并且不知何故rocket::request::FromParam参与其中但我从那里有点失落。
NaiveDate
可以表示为“自1月1日以来的天数”,类型为i32
。有方法self.num_days_from_ce()
和from_num_days_from_ce()
。我相信这是最方便的方式。 Documentation