summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-06-30 13:14:36 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-06-30 13:14:36 +0200
commit6b8c236b673dcd20e422f69ddb05a6736cf05bf3 (patch)
tree635287af89f8c963ef9973377737fe9d15f27cb5 /bin
parenta9bde370a3ae713464e0ac262ea7212b5d782d04 (diff)
parentf3c41915fdc3981a7bda536be731767a35d8d901 (diff)
Merge branch 'libimaghabit-dont-copy-comment-to-instance' into master
Diffstat (limited to 'bin')
-rw-r--r--bin/domain/imag-habit/src/main.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/bin/domain/imag-habit/src/main.rs b/bin/domain/imag-habit/src/main.rs
index fe4fb4b3..ad61fc76 100644
--- a/bin/domain/imag-habit/src/main.rs
+++ b/bin/domain/imag-habit/src/main.rs
@@ -480,12 +480,12 @@ fn show(rt: &Runtime) {
.map(String::from)
.unwrap(); // safe by clap
- fn instance_lister_fn(i: &FileLockEntry) -> Vec<String> {
+ fn instance_lister_fn(rt: &Runtime, i: &FileLockEntry) -> Vec<String> {
use libimagutil::date::date_to_string;
use libimaghabit::instance::HabitInstance;
let date = date_to_string(&i.get_date().map_err_trace_exit_unwrap());
- let comm = i.get_comment().map_err_trace_exit_unwrap();
+ let comm = i.get_comment(rt.store()).map_err_trace_exit_unwrap();
vec![date, comm]
}
@@ -523,7 +523,7 @@ fn show(rt: &Runtime) {
.unwrap_or_exit();
let mut empty = true;
- let _ = habit
+ let iter = habit
.linked_instances()
.map_err_trace_exit_unwrap()
.trace_unwrap_exit()
@@ -531,10 +531,17 @@ fn show(rt: &Runtime) {
debug!("Getting: {:?}", instance_id);
rt.store().get(instance_id).map_err_trace_exit_unwrap()
})
- .enumerate()
- .for_each(|(i, e)| {
+ .enumerate();
+
+ // We need to drop here because we iterate over instances and in the
+ // instance_lister_fn() we call instance.get_comment(), which internally tries to
+ // Store::get() the template object.
+ // This would fail because the template is already borrowed.
+ drop(habit);
+
+ iter.for_each(|(i, e)| {
let mut v = vec![format!("{}", i)];
- let mut instances = instance_lister_fn(&e);
+ let mut instances = instance_lister_fn(&rt, &e);
{
let _ = rt.report_touched(e.get_location()).unwrap_or_exit();