From 286703d802a433b78ebb334f864136b942f86b5c Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Wed, 25 Jan 2017 15:39:25 -0800 Subject: :shirt: --- src/lib.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2192df1..55266f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,62 +23,57 @@ static mut CONFIG: Option = None; static CONFIG_INIT: Once = ONCE_INIT; // Get the global configuration instance -fn global() -> Option<&'static mut Config> { +fn global() -> &'static mut Config { unsafe { CONFIG_INIT.call_once(|| { CONFIG = Some(Default::default()); }); - // TODO(@rust): One-line this if possible - if let Some(ref mut c) = CONFIG { - return Some(c); - } - - None + CONFIG.as_mut().unwrap() } } pub fn merge(source: T) -> Result<(), Box> where T: Source { - global().unwrap().merge(source) + global().merge(source) } pub fn set_env_prefix(prefix: &str) { - global().unwrap().set_env_prefix(prefix) + global().set_env_prefix(prefix) } pub fn set_default(key: &str, value: T) where T: Into { - global().unwrap().set_default(key, value) + global().set_default(key, value) } pub fn set(key: &str, value: T) where T: Into { - global().unwrap().set(key, value) + global().set(key, value) } pub fn get<'a, T>(key: &str) -> Option where T: TryFrom<&'a mut Value>, T: Default { - global().unwrap().get(key) + global().get(key) } pub fn get_str<'a>(key: &str) -> Option<&'a str> { - global().unwrap().get_str(key) + global().get_str(key) } pub fn get_int(key: &str) -> Option { - global().unwrap().get_int(key) + global().get_int(key) } pub fn get_float(key: &str) -> Option { - global().unwrap().get_float(key) + global().get_float(key) } pub fn get_bool(key: &str) -> Option { - global().unwrap().get_bool(key) + global().get_bool(key) } -- cgit v1.2.3