From e7d5e9ebc28a0b8232e7f84998c1c16b64bd50f8 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 4 Jan 2018 23:09:30 +0100 Subject: [PATCH] Refactoring: Use function chaining rather than matching --- lib/domain/libimagnotes/src/note.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/domain/libimagnotes/src/note.rs b/lib/domain/libimagnotes/src/note.rs index f7b0ed77..882fc481 100644 --- a/lib/domain/libimagnotes/src/note.rs +++ b/lib/domain/libimagnotes/src/note.rs @@ -46,13 +46,12 @@ impl Note for Entry { } fn get_name(&self) -> Result { - 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) {