From 939a31ad2b3cb18074b51a1659b1f79f9cd6bd3b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 4 Jun 2020 11:41:31 +0200 Subject: Collapse nested if-else Signed-off-by: Matthias Beyer --- bin/domain/imag-mail/src/lib.rs | 58 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/bin/domain/imag-mail/src/lib.rs b/bin/domain/imag-mail/src/lib.rs index 701a8070..e3cf099a 100644 --- a/bin/domain/imag-mail/src/lib.rs +++ b/bin/domain/imag-mail/src/lib.rs @@ -195,37 +195,35 @@ fn list(rt: &Runtime) -> Result<()> { .map(Ok); process(iter, &mut i, ¬much_connection, &list_format, rt, &mut out) + } else if scmd.is_present("query-from-stdin") { + let stdin = ::std::io::stdin(); + + let mailstore = store.with_connection(¬much_connection); + stdin.lock() + .lines() + .map(|r| r.map_err(Error::from).and_then(|query| { + debug!("Querying: {}", query); + let it = mailstore.query(&query)?; + + debug!("Found: {:?}", it); + let it = it.into_iter().map(Ok); + + process(it, &mut i, ¬much_connection, &list_format, rt, &mut out) + })) + .collect::>() } else { - if scmd.is_present("query-from-stdin") { - let stdin = ::std::io::stdin(); - - let mailstore = store.with_connection(¬much_connection); - stdin.lock() - .lines() - .map(|r| r.map_err(Error::from).and_then(|query| { - debug!("Querying: {}", query); - let it = mailstore.query(&query)?; - - debug!("Found: {:?}", it); - let it = it.into_iter().map(Ok); - - process(it, &mut i, ¬much_connection, &list_format, rt, &mut out) - })) - .collect::>() - } else { - // use StoreIds to find mails - let iter = rt.ids::()? - .ok_or_else(|| anyhow!("No ids supplied"))? - .into_iter() - .map(Ok) - .into_get_iter(rt.store()) - .map_inner_ok_or_else(|| anyhow!("Did not find one entry")) - .and_then_ok(|m| m.is_mail().map(|b| (b, m))) - .filter_ok(|tpl| tpl.0) - .map_ok(|tpl| tpl.1); - - process(iter, &mut i, ¬much_connection, &list_format, rt, &mut out) - } + // use StoreIds to find mails + let iter = rt.ids::()? + .ok_or_else(|| anyhow!("No ids supplied"))? + .into_iter() + .map(Ok) + .into_get_iter(rt.store()) + .map_inner_ok_or_else(|| anyhow!("Did not find one entry")) + .and_then_ok(|m| m.is_mail().map(|b| (b, m))) + .filter_ok(|tpl| tpl.0) + .map_ok(|tpl| tpl.1); + + process(iter, &mut i, ¬much_connection, &list_format, rt, &mut out) } } -- cgit v1.2.3