[][src]Trait router_xiaobei::prelude::RouteParam

pub trait RouteParam {
    fn from_str_param(param: &str) -> Result<Self, &str>
    where
        Self: Sized
; }

Enables a type to be used as a route paramer

This example is not tested
// 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

fn from_str_param(param: &str) -> Result<Self, &str> where
    Self: Sized

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

Loading content...

Implementors

impl<T> RouteParam for T where
    T: FromStr
[src]

Loading content...