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
macro_rules! enum_variant_from {
($target: ident, $variant: ident, $source: ident) => {
impl From<$source> for $target {
fn from(inner: $source) -> Self {
$target::$variant(inner)
}
}
};
}
macro_rules! enum_variant_into_result {
($source: ident, $variant: ident, $target: ident) => {
impl Into<Result<$target, $source>> for $source {
fn into(self) -> Result<$target, $source> {
match self {
$source::$variant(target) => Ok(target),
other => Err(other),
}
}
}
};
}
#[macro_export]
macro_rules! include_json_as {
($deserialize_as: ident, $file: expr) => {
serde_json::from_str::<$deserialize_as>(include_str!($file)).unwrap()
};
}