From 4bb0d0f073a7fb30d6a18cc6a3ebb7efb8b00aa5 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 4 Jan 2018 23:09:06 +0100 Subject: [PATCH] Refactor: Use function chaining instead of matching --- lib/domain/libimaglog/src/log.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/domain/libimaglog/src/log.rs b/lib/domain/libimaglog/src/log.rs index a172eae4..651d61a3 100644 --- a/lib/domain/libimaglog/src/log.rs +++ b/lib/domain/libimaglog/src/log.rs @@ -36,11 +36,10 @@ pub trait Log : DiaryEntry { impl Log for Entry { fn is_log(&self) -> Result { let location = "log.is_log"; - match self.get_header().read(location)? { - Some(&Value::Boolean(b)) => Ok(b), - Some(_) => Err(LE::from_kind(LEK::HeaderTypeError("boolean", location))), - None => Ok(false) - } + self.get_header() + .read(location)? + .ok_or(LE::from_kind(LEK::HeaderTypeError("boolean", location))) + .map(|v| v.as_bool().unwrap_or(false)) } fn make_log_entry(&mut self) -> Result<()> {