概要
HelloWorldが終わったので、さてもう少しやってみるか、となった時に複数ルーティングの仕方がわからなかったのでメモ。誰かの助けになればと思います。
やったこと
ルーティングの条件を.mount()
でつないでlaunch()
は最後で一回だけ呼ぶ。
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
#[get("/world")]
fn world() -> &'static str {
"Hello, world from routing!"
}
#[get("/")]
fn hello() -> &'static str {
"Hello, world!"
}
fn main() {
// 悪い例
// rocket::ignite().mount("/", routes![hello]).launch();
// rocket::ignite().mount("/hello", routes![world]).launch();
// 良い例
rocket::ignite().mount("/", routes![hello])
.mount("/hello", routes![world]).launch();
}