Refactoring: Use function chaining rather than matching
This commit is contained in:
parent
4bb0d0f073
commit
e7d5e9ebc2
1 changed files with 6 additions and 7 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue