Dedup code

This commit is contained in:
Matthias Beyer 2018-03-22 13:54:15 +01:00
parent 964b168f18
commit 2232f0153f

View file

@ -102,16 +102,7 @@ impl HabitTemplate for Entry {
store.create(id) store.create(id)
.map_err(From::from) .map_err(From::from)
.and_then(|mut entry| { .and_then(|entry| postprocess_instance(entry, name, date, comment))
{
let _ = entry.set_isflag::<IsHabitInstance>()?;
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)
})
} }
fn create_instance_today<'a>(&self, store: &'a Store) -> Result<FileLockEntry<'a>> { fn create_instance_today<'a>(&self, store: &'a Store) -> Result<FileLockEntry<'a>> {
@ -126,16 +117,7 @@ impl HabitTemplate for Entry {
store.create(id) store.create(id)
.map_err(From::from) .map_err(From::from)
.and_then(|mut entry| { .and_then(|entry| postprocess_instance(entry, name, date, comment))
{
let _ = entry.set_isflag::<IsHabitInstance>()?;
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)
})
} }
fn retrieve_instance_today<'a>(&self, store: &'a Store) -> Result<FileLockEntry<'a>> { fn retrieve_instance_today<'a>(&self, store: &'a Store) -> Result<FileLockEntry<'a>> {
@ -394,3 +376,19 @@ pub mod builder {
} }
fn postprocess_instance<'a>(mut entry: FileLockEntry<'a>,
name: String,
date: String,
comment: String)
-> Result<FileLockEntry<'a>>
{
{
let _ = entry.set_isflag::<IsHabitInstance>()?;
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)
}