Refactoring: Use function chaining rather than matching

This commit is contained in:
Matthias Beyer 2018-01-04 23:09:30 +01:00
parent 4bb0d0f073
commit e7d5e9ebc2

View file

@ -46,13 +46,12 @@ impl Note for Entry {
} }
fn get_name(&self) -> Result<String> { fn get_name(&self) -> Result<String> {
match self.get_header().read("note.name") { self.get_header()
Ok(Some(&Value::String(ref s))) => Ok(s.clone()), .read("note.name")
Ok(_) => { .chain_err(|| NEK::StoreReadError)?
Err(NE::from_kind(NEK::HeaderTypeError)).chain_err(|| NEK::StoreReadError) .and_then(Value::as_str)
}, .map(String::from)
Err(e) => Err(e).chain_err(|| NEK::StoreReadError) .ok_or(NE::from_kind(NEK::HeaderTypeError))
}
} }
fn set_text(&mut self, n: String) { fn set_text(&mut self, n: String) {