diff --git a/src/macros.rs b/src/macros.rs index f549c6f3..7c987eb9 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -27,4 +27,20 @@ macro_rules! for_match { } } }; +} + +/// Convenience macro getting a typed value +#[macro_export] +macro_rules! value_t { + ($m:ident.value_of($v:expr), $t:ty) => { + match $m.value_of($v) { + Some(v) => { + match v.parse::<$t>() { + Ok(val) => Ok(val), + Err(_) => Err(format!("{} isn't a valid {}",v,stringify!($t))), + } + }, + None => Err(format!("Argument not found")) + } + }; } \ No newline at end of file