Trait percy_router::prelude::RouteParam
source · pub trait RouteParam {
fn from_str_param(param: &str) -> Result<Self, &str>
where
Self: Sized;
}
Expand description
Enables a type to be used as a route paramer
ⓘ
// Example of a route param that only matches id's that are less than
// 10 characters long
#[route(path = "/path/to/:id")
fn my_route (id: ShortId) -> VirtualNode {
}
struct ShortId {
id: String,
length: usize
}
impl RouteParam for MyCustomType {
fn from_str (param: &str) -> Result<MyCustomType, ()> {
if param.len() > 10 {
Ok(MyCustomType {
length: param.len(), id: param.to_string()
})
} else {
Err(())
}
}
}