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> {
match self.get_header().read("note.name") {
Ok(Some(&Value::String(ref s))) => Ok(s.clone()),
Ok(_) => {
Err(NE::from_kind(NEK::HeaderTypeError)).chain_err(|| NEK::StoreReadError)
},
Err(e) => Err(e).chain_err(|| NEK::StoreReadError)
}
self.get_header()
.read("note.name")
.chain_err(|| NEK::StoreReadError)?
.and_then(Value::as_str)
.map(String::from)
.ok_or(NE::from_kind(NEK::HeaderTypeError))
}
fn set_text(&mut self, n: String) {