1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Yew routing extension

#![deny(missing_docs)]

mod router;
pub use crate::router::{Request, Route, RouterAgent};

#[macro_export]
/// Convinience macro for route creation
macro_rules! routes {
    ($($x:tt => $y:expr,)*) => (
        #[derive(Debug, PartialEq, Clone, Copy)]
        /// Possible child components
        pub enum RouterTarget {
            $($x,)*
        }

        /// Convert a RouterTarget into a Route
        impl<T> ::std::convert::Into<::yew_router::Route<T>> for RouterTarget where T: Default {
            fn into(self) -> ::yew_router::Route<T> {
                ::yew_router::Route {
                    fragment: Some(
                        match self {
                            $(RouterTarget::$x => $y,)*
                        }.into(),
                    ),
                    ..Default::default()
                }
            }
        }

        /// Convert a Route into a RouterTarget
        impl ::std::convert::Into<RouterTarget> for ::yew_router::Route<()> {
            fn into(self) -> RouterTarget {
                match self.fragment {
                    Some(f) => match f.as_str() {
                        $($y => RouterTarget::$x,)*
                        _ => RouterTarget::Error,
                    },
                    _ => RouterTarget::Error,
                }
            }
        }
    )
}