1#[macro_export]
4macro_rules! value {
22 ($($tt:tt)*) => {
23 {
24 let __value: $crate::CfgValue = ($($tt)*).into();
25 __value
26 }
27 };
28}
29
30#[macro_export]
31macro_rules! list {
43 ($($tt:tt),*) => {
44 value!(vec![$(value!($tt)),*])
45 };
46}
47
48macro_rules! from_int {
51 ($($type:ty),*) => {
52 $(
53 impl From<$type> for CfgValue {
54 fn from(i: $type) -> Self {
55 CfgValue::Int(i.into())
56 }
57 }
58 )*
59 };
60}
61
62macro_rules! from_float {
63 ($($type:ty),*) => {
64 $(
65 impl From<$type> for CfgValue {
66 fn from(f: $type) -> Self {
67 CfgValue::Float(f.into())
68 }
69 }
70 )*
71 };
72}
73
74macro_rules! from_str {
75 ($($type:ty),*) => {
76 $(
77 impl From<$type> for CfgValue {
78 fn from(s: $type) -> Self {
79 CfgValue::Str(s.into())
80 }
81 }
82 )*
83 };
84}
85
86macro_rules! doc_comment {
89 ($x:expr, $($tt:tt)*) => {
90 #[doc = $x]
91 $($tt)*
92 };
93}
94
95macro_rules! is_type {
96 ($fn_name:ident, $enum_type:path) => {
97 doc_comment! {
98 concat!("Checks whether the enum is a `", stringify!($enum_type), "`."),
99 pub fn $fn_name (&self) -> bool {
100 if let $enum_type(..) = self {
101 true
102 } else { false }
103 }
104 }
105 };
106
107 ($fn_name:ident [0], $enum_type:path) => {
108 doc_comment! {
109 concat!("Checks whether the enum is a `", stringify!($enum_type), "`."),
110 pub fn $fn_name (&self) -> bool {
111 if let $enum_type = self {
112 true
113 } else { false }
114 }
115 }
116 }
117}
118
119macro_rules! as_type {
120 ($fn_name:ident, $type:ty, $enum_type:path) => {
121 doc_comment! {
122 concat!("Returns a reference to the `", stringify!($type),
123 "`. Result is `None` if contents aren't a `", stringify!($enum_type), "`."),
124 pub fn $fn_name (&self) -> Option<&$type> {
125 if let $enum_type(x) = self {
126 Some(x)
127 } else { None }
128 }
129 }
130 };
131}
132
133macro_rules! as_mut_type {
134 ($fn_name:ident, $type:ty, $enum_type:path) => {
135 doc_comment! {
136 concat!("Returns a reference to the `", stringify!($type),
137 "`. Result is `None` if contents aren't a `", stringify!($enum_type), "`."),
138 pub fn $fn_name (&mut self) -> Option<&mut $type> {
139 if let $enum_type(x) = self {
140 Some(x)
141 } else { None }
142 }
143 }
144 };
145}