[][src]Trait yew_router_min::route::Switch

pub trait Switch: Sized {
    fn from_path(path: &str) -> Option<Self>;

    fn from_route(part: String) -> Option<Self> { ... }
}

Derivable routing trait that allows instances of implementors to be constructed from Routes.

Note

Don't try to implement this yourself, rely on the derive macro.

Example

use yew_router_min::Switch;
#[derive(Debug, Switch, PartialEq)]
enum TestEnum {
    #[to = "/test/route"]
    TestRoute,
    #[to = "/capture/string/{path}"]
    CaptureString { path: String },
    #[to = "/capture/number/{num}"]
    CaptureNumber { num: usize },
    #[to = "/capture/unnamed/{doot}"]
    CaptureUnnamed(String),
}

assert_eq!(
    TestEnum::from_path("/test/route"),
    Some(TestEnum::TestRoute)
);
assert_eq!(
    TestEnum::from_path("/capture/string/lorem"),
    Some(TestEnum::CaptureString {
        path: "lorem".to_string()
    })
);
assert_eq!(
    TestEnum::from_path("/capture/number/22"),
    Some(TestEnum::CaptureNumber { num: 22 })
);
assert_eq!(
    TestEnum::from_path("/capture/unnamed/lorem"),
    Some(TestEnum::CaptureUnnamed("lorem".to_string()))
);

Required methods

fn from_path(path: &str) -> Option<Self>

Based on a route, possibly produce an itself.

Loading content...

Provided methods

fn from_route(part: String) -> Option<Self>

Parses route.

Loading content...

Implementors

impl<T: FromStr> Switch for T[src]

impl<U: Switch + Debug> Switch for AllowMissing<U>[src]

impl<U: Switch> Switch for LeadingSlash<U>[src]

Loading content...