Replace matching with function chaining

This commit is contained in:
Matthias Beyer 2018-01-04 20:27:29 +01:00
parent dbd9a2faaf
commit fa8ac03701

View file

@ -80,21 +80,18 @@ pub fn fetch_config(searchpath: &PathBuf) -> Result<Value> {
s s
}; };
match ::toml::de::from_str::<::toml::Value>(&content[..]) { ::toml::de::from_str::<::toml::Value>(&content[..])
Ok(res) => Some(res), .map(Some)
Err(e) => { .unwrap_or_else(|e| {
let line_col = e let line_col = e
.line_col() .line_col()
.map(|(line, col)| { .map(|(line, col)| format!("Line {}, Column {}", line, col))
format!("Line {}, Column {}", line, col)
})
.unwrap_or_else(|| String::from("Line unknown, Column unknown")); .unwrap_or_else(|| String::from("Line unknown, Column unknown"));
let _ = write!(stderr(), "Config file parser error at {}", line_col); let _ = write!(stderr(), "Config file parser error at {}", line_col);
trace_error(&e); trace_error(&e);
None None
} })
}
}) })
.nth(0) .nth(0)
.ok_or(RE::from_kind(REK::ConfigNoConfigFileFound)) .ok_or(RE::from_kind(REK::ConfigNoConfigFileFound))