From 391ae705356a382d40172ee32e525797d41b68db Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 21 Feb 2020 19:24:54 +0100 Subject: Shrink iteration to collect ids and then print rather than three steps Signed-off-by: Matthias Beyer --- bin/domain/imag-mail/src/lib.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/bin/domain/imag-mail/src/lib.rs b/bin/domain/imag-mail/src/lib.rs index 03a1a1b6..b2f597b2 100644 --- a/bin/domain/imag-mail/src/lib.rs +++ b/bin/domain/imag-mail/src/lib.rs @@ -201,8 +201,8 @@ fn list(rt: &Runtime) -> Result<()> { where I: Iterator>> { debug!("Processing tree"); - let iter = if find_root { - let iter = iter.and_then_ok(|fle| { + let ids : Vec<_> = if find_root { + iter.and_then_ok(|fle| { trace!("Loading: {}", fle.get_location()); let id = fle .load(conn)? @@ -214,18 +214,17 @@ fn list(rt: &Runtime) -> Result<()> { drop(fle); id - }); - - Box::new(iter) as Box>> + }) + .and_then_ok(|id: String| mailstore.get_mailtree(&id)) + .collect::>>() } else { - let iter = iter.and_then_ok(|fle| fle.get_cached_id()); - Box::new(iter) as Box>> - }; + iter.and_then_ok(|fle| fle.get_cached_id()) + .and_then_ok(|id: String| mailstore.get_mailtree(&id)) + .collect::>>() + }?; trace!("Getting mailtree now!"); - iter.and_then_ok(|id: String| mailstore.get_mailtree(&id)) - .collect::>>()? - .into_iter() + ids.into_iter() .map(|mt| print_traverse(&mailstore, mt, i, conn, list_format, rt, out)) .collect::>>() .map(|_| ()) -- cgit v1.2.3