Replace matching with function chaining

This commit is contained in:
Matthias Beyer 2018-01-04 20:44:11 +01:00
parent fa8ac03701
commit 4184a1e5d0

View file

@ -115,20 +115,16 @@ pub fn override_config(val: &mut Value, v: Vec<String>) -> Result<()> {
warn!("Could split at '=' - will be ignore override"); warn!("Could split at '=' - will be ignore override");
None None
})) }))
.map(|(k, v)| val .map(|(k, v)| {
.read(&k[..]) let value = val
.chain_err(|| REK::ConfigTOMLParserError) .read(&k)
.map(|toml| match toml { .chain_err(|| REK::ConfigTOMLParserError)?
Some(value) => match into_value(value, v) { .ok_or(RE::from_kind(REK::ConfigOverrideKeyNotAvailable))?;
Some(v) => {
info!("Successfully overridden: {} = {}", k, v); into_value(value, v)
Ok(()) .map(|v| info!("Successfully overridden: {} = {}", k, v))
}, .ok_or_else(|| RE::from_kind(REK::ConfigOverrideTypeNotMatching))
None => Err(RE::from_kind(REK::ConfigOverrideTypeNotMatching)), });
},
None => Err(RE::from_kind(REK::ConfigOverrideKeyNotAvailable)),
})
);
for elem in iter { for elem in iter {
let _ = try!(elem.chain_err(|| REK::ConfigOverrideError)); let _ = try!(elem.chain_err(|| REK::ConfigOverrideError));