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(())
        }
    }
}

Required Methods§

Given some parameter, return Self

For example, for the route path:

/route/path/:id

And incoming path

/route/path/55

If Self is a u32 we would return 55

Implementors§