diff --git a/lib/domain/libimaghabit/src/habit.rs b/lib/domain/libimaghabit/src/habit.rs index f5d984fb..ea8ed7d4 100644 --- a/lib/domain/libimaghabit/src/habit.rs +++ b/lib/domain/libimaghabit/src/habit.rs @@ -102,16 +102,7 @@ impl HabitTemplate for Entry { store.create(id) .map_err(From::from) - .and_then(|mut entry| { - { - let _ = entry.set_isflag::()?; - let hdr = entry.get_header_mut(); - let _ = hdr.insert("habit.instance.name", Value::String(name))?; - let _ = hdr.insert("habit.instance.date", Value::String(date))?; - let _ = hdr.insert("habit.instance.comment", Value::String(comment))?; - } - Ok(entry) - }) + .and_then(|entry| postprocess_instance(entry, name, date, comment)) } fn create_instance_today<'a>(&self, store: &'a Store) -> Result> { @@ -126,16 +117,7 @@ impl HabitTemplate for Entry { store.create(id) .map_err(From::from) - .and_then(|mut entry| { - { - let _ = entry.set_isflag::()?; - let hdr = entry.get_header_mut(); - let _ = hdr.insert("habit.instance.name", Value::String(name))?; - let _ = hdr.insert("habit.instance.date", Value::String(date))?; - let _ = hdr.insert("habit.instance.comment", Value::String(comment))?; - } - Ok(entry) - }) + .and_then(|entry| postprocess_instance(entry, name, date, comment)) } fn retrieve_instance_today<'a>(&self, store: &'a Store) -> Result> { @@ -394,3 +376,19 @@ pub mod builder { } +fn postprocess_instance<'a>(mut entry: FileLockEntry<'a>, + name: String, + date: String, + comment: String) + -> Result> +{ + { + let _ = entry.set_isflag::()?; + let hdr = entry.get_header_mut(); + let _ = hdr.insert("habit.instance.name", Value::String(name))?; + let _ = hdr.insert("habit.instance.date", Value::String(date))?; + let _ = hdr.insert("habit.instance.comment", Value::String(comment))?; + } + Ok(entry) +} +