zola/components/templates/src/global_fns/macros.rs

26 lines
632 B
Rust
Raw Normal View History

2018-10-29 19:13:09 +00:00
#[macro_export]
macro_rules! required_arg {
($ty: ty, $e: expr, $err: expr) => {
match $e {
Some(v) => match from_value::<$ty>(v.clone()) {
Ok(u) => u,
2018-10-31 07:18:57 +00:00
Err(_) => return Err($err.into()),
2018-10-29 19:13:09 +00:00
},
2018-10-31 07:18:57 +00:00
None => return Err($err.into()),
2018-10-29 19:13:09 +00:00
}
};
}
#[macro_export]
macro_rules! optional_arg {
($ty: ty, $e: expr, $err: expr) => {
match $e {
Some(v) => match from_value::<$ty>(v.clone()) {
Ok(u) => Some(u),
2018-10-31 07:18:57 +00:00
Err(_) => return Err($err.into()),
2018-10-29 19:13:09 +00:00
},
2018-10-31 07:18:57 +00:00
None => None,
2018-10-29 19:13:09 +00:00
}
};
}