1
2#[macro_export]
3#[doc(hidden)]
4macro_rules! __string_enum {
5 ($name:ident { $($variant:ident = $value:expr, )* }) => {
6 impl std::fmt::Display for $name {
7 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8 match self {
9 $( $name::$variant => write!(f, $value), )*
10 }
11 }
12 }
13
14 impl std::str::FromStr for $name {
15 type Err = crate::Error;
16
17 fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
18 match s {
19 $($value => Ok($name::$variant),)*
20 s => Err(crate::Error::CommonError(format!(
21 "Unkown Value. Found `{}`, Expected `{}`",
22 s,
23 stringify!($($value,)*)
24 )))
25 }
26 }
27 }
28 }
29}
30
31#[macro_export]
32#[doc(hidden)]
33macro_rules! __setter {
34 ($field:ident: Option<$ty:ty>) => {
35 #[inline(always)]
36 pub fn $field<T: Into<$ty>>(mut self, value: T) -> Self {
37 self.$field = Some(value.into());
38 self
39 }
40 };
41 (children: Vec<$ty:ty>) => {
42 #[inline(always)]
43 pub fn add_child<T: Into<$ty>>(mut self, value: T) -> Self {
44 self.children.push(value.into());
45 self
46 }
47 #[inline(always)]
48 pub fn children<T: Into<Vec<$ty>>>(mut self, value: T) -> Self {
49 self.children = value.into();
50 self
51 }
52 };
53 ($field:ident: $ty:ty) => {
54 #[inline(always)]
55 pub fn $field<T: Into<$ty>>(mut self, value: T) -> Self {
56 self.$field = value.into();
57 self
58 }
59 };
60}
61
62
63
64#[macro_export]
65#[doc(hidden)]
66macro_rules! __ref_setter {
67 ($field:ident: Option<$ty:ty>) => {
68 #[inline(always)]
69 pub fn $field<T: Into<$ty>>(&mut self, value: T) -> &mut Self {
70 self.$field = Some(value.into());
71 self
72 }
73 };
74 ($field:ident: $ty:ty) => {
75 #[inline(always)]
76 pub fn $field<T: Into<$ty>>(&mut self, value: T) -> &mut Self {
77 self.$field = value.into();
78 self
79 }
80 };
81}