lexa_framework/macros_rules/
routes.rs1#[macro_export]
12macro_rules! routes {
13 (
14 pub enum $enum_route:ident<$l:lifetime> {
15 $(
16 #[route(url = $url:literal)]
17 $variant:ident
18 $({
19 $($field:ident : $type:ty),*
20 })?
21 ),*,
22 }
23 ) => {
24 pub enum $enum_route<$l> {
25 #[non_exhaustive] PhantomData(std::marker::PhantomData<&$l ()>),
26 $(
27 $variant $({
28 $($field : $type),*
29 })?,
30 )*
31 }
32
33 impl std::fmt::Display for $enum_route<'_> {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 let route = match self {
36 Self::PhantomData(_) => unimplemented!(),
37 $(
38 | Self::$variant $({ $($field),* })? => format!($url),
39 )*
40 };
41 write!(f, "{route}")
42 }
43 }
44
45 impl std::fmt::Debug for $enum_route<'_> {
46 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 match self {
48 Self::PhantomData(_) => unimplemented!(),
49 $(
50 #[allow(dead_code)]
51 | Self::$variant $({ $($field),* })? => write!(f, stringify!($variant)),
52 )*
53 }
54 }
55 }
56 };
57}