From fa8ac037017bffbe4a72bea498276dd65623ec1c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 4 Jan 2018 20:27:29 +0100 Subject: [PATCH] Replace matching with function chaining --- lib/core/libimagrt/src/configuration.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/core/libimagrt/src/configuration.rs b/lib/core/libimagrt/src/configuration.rs index deafe8cf..680a4d2c 100644 --- a/lib/core/libimagrt/src/configuration.rs +++ b/lib/core/libimagrt/src/configuration.rs @@ -80,21 +80,18 @@ pub fn fetch_config(searchpath: &PathBuf) -> Result { s }; - match ::toml::de::from_str::<::toml::Value>(&content[..]) { - Ok(res) => Some(res), - Err(e) => { + ::toml::de::from_str::<::toml::Value>(&content[..]) + .map(Some) + .unwrap_or_else(|e| { let line_col = e .line_col() - .map(|(line, col)| { - format!("Line {}, Column {}", line, col) - }) + .map(|(line, col)| format!("Line {}, Column {}", line, col)) .unwrap_or_else(|| String::from("Line unknown, Column unknown")); let _ = write!(stderr(), "Config file parser error at {}", line_col); trace_error(&e); None - } - } + }) }) .nth(0) .ok_or(RE::from_kind(REK::ConfigNoConfigFileFound))