yew_router_macro/lib.rs
1mod routable_derive;
2use routable_derive::{routable_derive_impl, Routable};
3use syn::parse_macro_input;
4
5/// Derive macro used to mark an enum as Routable.
6///
7/// This macro can only be used on enums. Every varient of the macro needs to be marked
8/// with the `at` attribute to specify the URL of the route. It generates an implementation of
9/// `yew_router::Routable` trait and `const`s for the routes passed which are used with `Route`
10/// component.
11///
12/// # Example
13///
14/// ```
15/// # use yew_router::Routable;
16/// #[derive(Debug, Clone, Copy, PartialEq, Routable)]
17/// enum Routes {
18/// #[at("/")]
19/// Home,
20/// #[at("/secure")]
21/// Secure,
22/// #[at("/404")]
23/// NotFound,
24/// }
25/// ```
26#[proc_macro_derive(Routable, attributes(at, not_found))]
27pub fn routable_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
28 let input = parse_macro_input!(input as Routable);
29 routable_derive_impl(input).into()
30}