Skip to main content

FromPath

Derive Macro FromPath 

Source
#[derive(FromPath)]
Available on crate feature macros only.
Expand description

Derive rust_web_server::handler::FromPath for a struct with named fields: one route parameter per field, by name, each parsed with FromStr. A typed handler’s route must have exactly these parameters (checked at compile time).

ⓘ
#[derive(rust_web_server::FromPath)]
struct PostKey { id: u64, slug: String }

#[get("/posts/{id}/{slug}")]
fn post(Path(key): Path<PostKey>) -> String { format!("{} {}", key.id, key.slug) }