From dbd9a2faafe1e62c6af827c4557272a2e0864f00 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 4 Jan 2018 20:26:42 +0100 Subject: [PATCH] Replace matching with function chaining --- lib/domain/libimaghabit/src/habit.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/domain/libimaghabit/src/habit.rs b/lib/domain/libimaghabit/src/habit.rs index ab22ed09..29794101 100644 --- a/lib/domain/libimaghabit/src/habit.rs +++ b/lib/domain/libimaghabit/src/habit.rs @@ -219,11 +219,10 @@ impl HabitTemplate for Entry { } fn habit_until_date(&self) -> Result> { - match self.get_header().read("habit.template.until")? { - Some(&Value::String(ref s)) => Ok(Some(s.clone())), - Some(_) => Err(HEK::HeaderTypeError("habit.template.until", "String").into()), - None => Ok(None), - } + self.get_header() + .read("habit.template.until")? + .map(|v| v.as_str().map(String::from)) + .ok_or(HEK::HeaderTypeError("habit.template.until", "String").into()) } fn instance_id_for(habit_name: &String, habit_date: &NaiveDate) -> Result {