From 1be551d4f53d7648ea10f074bffa86b1e0cbd86b Mon Sep 17 00:00:00 2001 From: kageru Date: Sun, 19 Apr 2020 19:07:54 +0200 Subject: [PATCH] improve sum_as_str --- src/timesheet.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/timesheet.rs b/src/timesheet.rs index f4807c3..6232018 100644 --- a/src/timesheet.rs +++ b/src/timesheet.rs @@ -94,10 +94,10 @@ impl TimeSheet { pub fn sum_as_str(&self) -> String { let total = self .times - .windows(2) - .fold(time::Duration::zero(), |total, ts| { - let last = ts[0].time; - let next = ts[1].time; + .iter() + .map(|tp| tp.time) + .tuple_windows() + .fold(time::Duration::zero(), |total, (last, next)| { total + (next - last) }); format_duration(&total)