zola/components/templates/src/global_fns/macros.rs
Vincent Prouillet b7ce4e59fb rustfmt
2018-10-31 08:18:57 +01:00

26 lines
632 B
Rust

#[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,
Err(_) => return Err($err.into()),
},
None => return Err($err.into()),
}
};
}
#[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),
Err(_) => return Err($err.into()),
},
None => None,
}
};
}