Macro rocket::routes

source ยท
routes!() { /* proc-macro */ }
Expand description

Generates a Vec of Routes from a set of route paths.

The routes! macro expands a list of route paths into a Vec of their corresponding Route structures. For example, given the following routes:

#[get("/")]
fn index() { /* .. */ }

mod person {
    #[post("/hi/<person>")]
    pub fn hello(person: String) { /* .. */ }
}

The routes! macro can be used as:

let my_routes = routes![index, person::hello];
assert_eq!(my_routes.len(), 2);

let index_route = &my_routes[0];
assert_eq!(index_route.method, Some(Method::Get));
assert_eq!(index_route.name.as_ref().unwrap(), "index");
assert_eq!(index_route.uri.path(), "/");

let hello_route = &my_routes[1];
assert_eq!(hello_route.method, Some(Method::Post));
assert_eq!(hello_route.name.as_ref().unwrap(), "hello");
assert_eq!(hello_route.uri.path(), "/hi/<person>");

The grammar for routes! is defined as:

routes := PATH (',' PATH)*

PATH := a path, as defined by Rust