From 4184a1e5d0ec396fae739e8819040ced4074a78b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 4 Jan 2018 20:44:11 +0100 Subject: [PATCH] Replace matching with function chaining --- lib/core/libimagrt/src/configuration.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/core/libimagrt/src/configuration.rs b/lib/core/libimagrt/src/configuration.rs index 680a4d2c..b4c931cd 100644 --- a/lib/core/libimagrt/src/configuration.rs +++ b/lib/core/libimagrt/src/configuration.rs @@ -115,20 +115,16 @@ pub fn override_config(val: &mut Value, v: Vec) -> Result<()> { warn!("Could split at '=' - will be ignore override"); None })) - .map(|(k, v)| val - .read(&k[..]) - .chain_err(|| REK::ConfigTOMLParserError) - .map(|toml| match toml { - Some(value) => match into_value(value, v) { - Some(v) => { - info!("Successfully overridden: {} = {}", k, v); - Ok(()) - }, - None => Err(RE::from_kind(REK::ConfigOverrideTypeNotMatching)), - }, - None => Err(RE::from_kind(REK::ConfigOverrideKeyNotAvailable)), - }) - ); + .map(|(k, v)| { + let value = val + .read(&k) + .chain_err(|| REK::ConfigTOMLParserError)? + .ok_or(RE::from_kind(REK::ConfigOverrideKeyNotAvailable))?; + + into_value(value, v) + .map(|v| info!("Successfully overridden: {} = {}", k, v)) + .ok_or_else(|| RE::from_kind(REK::ConfigOverrideTypeNotMatching)) + }); for elem in iter { let _ = try!(elem.chain_err(|| REK::ConfigOverrideError));