From dead8e444b97fc82d923b178e47ab721f6dc1e78 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Wed, 25 Dec 2019 22:38:55 +0300 Subject: [PATCH] refac: reuse init variable macro --- itconfig/src/lib.rs | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/itconfig/src/lib.rs b/itconfig/src/lib.rs index 7734197..375824f 100644 --- a/itconfig/src/lib.rs +++ b/itconfig/src/lib.rs @@ -407,6 +407,21 @@ macro_rules! __itconfig_impl { #[macro_export] #[doc(hidden)] macro_rules! __itconfig_variable { + // Add method without default value + ( + name = $name:ident, + env_name = $env_name:expr, + ty = $ty:ty, + ) => { + __itconfig_variable! { + name = $name, + env_name = $env_name, + ty = $ty, + default = panic!(format!(r#"Cannot read "{}" environment variable"#, + $env_name.to_uppercase())), + } + }; + // Add method with default value ( name = $name:ident, @@ -421,23 +436,6 @@ macro_rules! __itconfig_variable { } }; - // Add method without default value - ( - name = $name:ident, - env_name = $env_name:expr, - ty = $ty:ty, - ) => { - pub fn $name() -> $ty { - env::var($env_name.to_uppercase()) - .map(|val| EnvValue::from(val).into()) - .unwrap_or_else(|_| { - panic!(format!(r#"Cannot read "{}" environment variable"#, - $env_name.to_uppercase())) - }) - - } - }; - // Invalid syntax ($($tokens:tt)*) => { __itconfig_invalid_syntax!();