Make code more idomatic

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2018-11-08 16:08:46 +01:00
parent a2eae99a39
commit 35291d68ad

View file

@ -315,7 +315,7 @@ fn today(rt: &Runtime, future: bool) {
info!("No Habits due today."); info!("No Habits due today.");
info!("Upcoming:"); info!("Upcoming:");
// list `n` which are relevant in the future. // list `n` which are relevant in the future.
for element in relevant.iter().take(n) { relevant.iter().take(n).for_each(|element| {
let date = element.next_instance_date().map_err_trace_exit_unwrap(1); let date = element.next_instance_date().map_err_trace_exit_unwrap(1);
let name = element.habit_name().map_err_trace_exit_unwrap(1); let name = element.habit_name().map_err_trace_exit_unwrap(1);
@ -328,7 +328,7 @@ fn today(rt: &Runtime, future: bool) {
info!(" * {date}: {name}", date = date, name = name); info!(" * {date}: {name}", date = date, name = name);
} }
} }
} });
} else { } else {
fn lister_fn(h: &FileLockEntry) -> Vec<String> { fn lister_fn(h: &FileLockEntry) -> Vec<String> {
debug!("Listing: {:?}", h); debug!("Listing: {:?}", h);
@ -354,9 +354,9 @@ fn today(rt: &Runtime, future: bool) {
table.set_titles(Row::new(header)); table.set_titles(Row::new(header));
let mut empty = true; let mut empty = true;
for (i, e) in relevant.into_iter() relevant
.filter(|habit| { .into_iter()
show_done || { .filter(|habit| show_done || {
habit habit
.next_instance_date() .next_instance_date()
.map_err_trace_exit_unwrap(1) .map_err_trace_exit_unwrap(1)
@ -365,10 +365,9 @@ fn today(rt: &Runtime, future: bool) {
.map_err_trace_exit_unwrap(1) .map_err_trace_exit_unwrap(1)
}) })
.unwrap_or(false) .unwrap_or(false)
}
}) })
.enumerate() .enumerate()
{ .for_each(|(i, e)| {
let mut v = vec![format!("{}", i)]; let mut v = vec![format!("{}", i)];
let mut list = lister_fn(&e); let mut list = lister_fn(&e);
@ -381,7 +380,7 @@ fn today(rt: &Runtime, future: bool) {
v.append(&mut list); v.append(&mut list);
table.add_row(v.iter().map(|s| Cell::new(s)).collect()); table.add_row(v.iter().map(|s| Cell::new(s)).collect());
empty = false; empty = false;
} });
if !empty { if !empty {
let _ = table.print(&mut rt.stdout()).to_exit_code().unwrap_or_exit(); let _ = table.print(&mut rt.stdout()).to_exit_code().unwrap_or_exit();