diff --git a/bin/domain/imag-habit/src/main.rs b/bin/domain/imag-habit/src/main.rs index 4e625923..ccb8e71e 100644 --- a/bin/domain/imag-habit/src/main.rs +++ b/bin/domain/imag-habit/src/main.rs @@ -518,7 +518,7 @@ fn done(rt: &Runtime) { relevant }; - for r in relevant.iter() { + for mut r in relevant { let next_instance_name = r.habit_name().map_err_trace_exit_unwrap(1); let next_instance_date = r.next_instance_date().map_err_trace_exit_unwrap(1); if let Some(next) = next_instance_date { diff --git a/lib/domain/libimaghabit/src/habit.rs b/lib/domain/libimaghabit/src/habit.rs index 7119e9d5..e3963b7a 100644 --- a/lib/domain/libimaghabit/src/habit.rs +++ b/lib/domain/libimaghabit/src/habit.rs @@ -55,18 +55,19 @@ pub trait HabitTemplate : Sized { /// /// It uses `Store::retrieve()` underneath. So if there is already an instance for the day /// passed, this will simply return the instance. - fn create_instance_with_date<'a>(&self, store: &'a Store, date: &NaiveDate) + fn create_instance_with_date<'a>(&mut self, store: &'a Store, date: &NaiveDate) -> Result>; /// Shortcut for calling `Self::create_instance_with_date()` with an instance of /// `::chrono::Local::today().naive_local()`. - fn create_instance_today<'a>(&self, store: &'a Store) -> Result>; + fn create_instance_today<'a>(&mut self, store: &'a Store) -> Result>; /// Same as `HabitTemplate::create_instance_with_date()` but uses `Store::retrieve` internally. - fn retrieve_instance_with_date<'a>(&self, store: &'a Store, date: &NaiveDate) -> Result>; + fn retrieve_instance_with_date<'a>(&mut self, store: &'a Store, date: &NaiveDate) + -> Result>; /// Same as `HabitTemplate::create_instance_today()` but uses `Store::retrieve` internally. - fn retrieve_instance_today<'a>(&self, store: &'a Store) -> Result>; + fn retrieve_instance_today<'a>(&mut self, store: &'a Store) -> Result>; /// Get instances for this template fn linked_instances(&self) -> Result; @@ -96,7 +97,7 @@ provide_kindflag_path!(pub IsHabitTemplate, "habit.template.is_habit_template"); impl HabitTemplate for Entry { - fn create_instance_with_date<'a>(&self, store: &'a Store, date: &NaiveDate) -> Result> { + fn create_instance_with_date<'a>(&mut self, store: &'a Store, date: &NaiveDate) -> Result> { let name = self.habit_name()?; let comment = self.habit_comment()?; let date = date_to_string(date); @@ -104,14 +105,14 @@ impl HabitTemplate for Entry { store.create(id) .map_err(From::from) - .and_then(|entry| postprocess_instance(entry, name, date, comment)) + .and_then(|entry| postprocess_instance(entry, name, date, comment, self)) } - fn create_instance_today<'a>(&self, store: &'a Store) -> Result> { + fn create_instance_today<'a>(&mut self, store: &'a Store) -> Result> { self.create_instance_with_date(store, &Local::today().naive_local()) } - fn retrieve_instance_with_date<'a>(&self, store: &'a Store, date: &NaiveDate) -> Result> { + fn retrieve_instance_with_date<'a>(&mut self, store: &'a Store, date: &NaiveDate) -> Result> { let name = self.habit_name()?; let comment = self.habit_comment()?; let date = date_to_string(date); @@ -119,10 +120,10 @@ impl HabitTemplate for Entry { store.create(id) .map_err(From::from) - .and_then(|entry| postprocess_instance(entry, name, date, comment)) + .and_then(|entry| postprocess_instance(entry, name, date, comment, self)) } - fn retrieve_instance_today<'a>(&self, store: &'a Store) -> Result> { + fn retrieve_instance_today<'a>(&mut self, store: &'a Store) -> Result> { self.retrieve_instance_with_date(store, &Local::today().naive_local()) } @@ -401,7 +402,8 @@ pub mod builder { fn postprocess_instance<'a>(mut entry: FileLockEntry<'a>, name: String, date: String, - comment: String) + comment: String, + template: &mut Entry) -> Result> { { @@ -411,6 +413,9 @@ fn postprocess_instance<'a>(mut entry: FileLockEntry<'a>, let _ = hdr.insert("habit.instance.date", Value::String(date))?; let _ = hdr.insert("habit.instance.comment", Value::String(comment))?; } + + entry.add_internal_link(template)?; + Ok(entry) }