pub fn path_params<T: DeserializeOwned, B>(
req: &Request<B>,
) -> Result<T, ServeError>Expand description
Extract path parameters from the request and deserialize into type T.
Path parameters are decoded and matched by the router, then deserialized
via serde’s MapDeserializer. Returns 400 Bad Request if deserialization
fails (e.g., an unparseable segment for a numeric type) or if the route
captured no parameters at all — asking a param-less route for its params is
a bad request, not a server fault, and it used to report 500.
§Example
ⓘ
use serde::Deserialize;
use mini_serve::path_params;
#[derive(Deserialize)]
struct ItemId {
id: u64,
}
let item = path_params::<ItemId, _>(req)?;
println!("Item ID: {}", item.id);