diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2018-11-07 13:51:42 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2018-11-07 13:51:42 +0100 |
commit | 8d0ae1058ed2ae8627d8b0b109ca4b2fb1a62ed9 (patch) | |
tree | f0cbec0efbd70e07ca5cd6479b24a823a51ebe92 /bin/domain/imag-log/src/main.rs | |
parent | 07cbecc1baae777f4c00cf3c1e25a18fb2c0ff7b (diff) |
Make code more functional by more function chaining
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'bin/domain/imag-log/src/main.rs')
-rw-r--r-- | bin/domain/imag-log/src/main.rs | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/bin/domain/imag-log/src/main.rs b/bin/domain/imag-log/src/main.rs index 5e09efce..0be4003e 100644 --- a/bin/domain/imag-log/src/main.rs +++ b/bin/domain/imag-log/src/main.rs @@ -185,7 +185,14 @@ fn get_diary_name(rt: &Runtime) -> String { .ok_or_else(|| Error::from(err_msg("Configuration not present, cannot continue"))) .map_err_trace_exit_unwrap(1); - let logs = cfg + let current_log = cfg + .read_string("log.default") + .map_err(Error::from) + .map_err_trace_exit_unwrap(1) + .ok_or_else(|| Error::from(err_msg("Configuration missing: 'log.default'"))) + .map_err_trace_exit_unwrap(1); + + if cfg .read("log.logs") .map_err(Error::from) .map_err_trace_exit_unwrap(1) @@ -193,34 +200,26 @@ fn get_diary_name(rt: &Runtime) -> String { .map_err_trace_exit_unwrap(1) .as_array() .ok_or_else(|| Error::from(err_msg("Configuration 'log.logs' is not an Array"))) - .map_err_trace_exit_unwrap(1); - - if !logs.iter().all(|e| is_match!(e, &Value::String(_))) { - error!("Configuration 'log.logs' is not an Array<String>!"); - ::std::process::exit(1); - } - - let logs = logs - .into_iter() + .map_err_trace_exit_unwrap(1) + .iter() + .map(|e| if is_match!(e, &Value::String(_)) { + error!("Configuration 'log.logs' is not an Array<String>!"); + ::std::process::exit(1) + } else { + e + }) .map(Value::as_str) - .map(Option::unwrap) + .map(Option::unwrap) // safe by map from above .map(String::from) - .collect::<Vec<String>>(); - - let current_log = cfg - .read_string("log.default") - .map_err(Error::from) - .map_err_trace_exit_unwrap(1) - .ok_or_else(|| Error::from(err_msg("Configuration missing: 'log.default'"))) - .map_err_trace_exit_unwrap(1); - - if !logs.contains(¤t_log) { + .filter(|log| log == ¤t_log) + .next() + .is_none() + { error!("'log.logs' does not contain 'log.default'"); ::std::process::exit(1) } else { current_log.into() } - } fn get_log_text(rt: &Runtime) -> String { |