changeset 617:87a78343140e rust

Duration::sum works now
author Matt Johnston <matt@ucc.asn.au>
date Tue, 21 Mar 2017 19:13:49 +0800
parents a85c0c9bc1fa
children 2d65a9f0bed3
files rust/src/types.rs
diffstat 1 files changed, 5 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/rust/src/types.rs	Wed Mar 08 23:08:14 2017 +0800
+++ b/rust/src/types.rs	Tue Mar 21 19:13:49 2017 +0800
@@ -243,9 +243,7 @@
             let end = p.end.unwrap_or_else(|| Instant::now());
             end - p.start
         });
-        // TODO rust 1.16: impl Sum for Duration 
-        // durs.sum()
-        durs.fold(Duration::new(0,0), |acc, d| acc + d)
+        durs.sum()
     }
 
     fn trim(&mut self) {
@@ -268,13 +266,12 @@
 
 /// Takes a stream and returns a stream without errors.
 pub fn consume_errors<S>(s: S) -> Box<Stream<Item=S::Item, Error=S::Error>> 
-// XXX not sure why 'static is really necessary here?
     where 
     S: Stream+Send+'static, 
     <S as Stream>::Error: std::fmt::Display+Send+'static,
     <S as Stream>::Item: Send+'static,
-    {
-    s.then(|r| {
+{
+    let f = s.then(|r| {
         match r {
             Ok(v) => Ok(Some(v)),
             Err(e) => {
@@ -283,5 +280,6 @@
             }
         }
     })
-    .filter_map(|p| p).boxed()
+    .filter_map(|p| p);
+    Box::new(f)
 }