Sum for Duration.

This commit is contained in:
Clar Charr 2016-12-30 14:22:47 -05:00
parent 7f2d2afa91
commit 03b66ead69

View File

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use iter::Sum;
use ops::{Add, Sub, Mul, Div, AddAssign, SubAssign, MulAssign, DivAssign};
const NANOS_PER_SEC: u32 = 1_000_000_000;
@ -356,6 +357,20 @@ impl DivAssign<u32> for Duration {
}
}
#[stable(feature = "duration_sum", since = "1.16.0")]
impl Sum for Duration {
fn sum<I: Iterator<Item=Duration>>(iter: I) -> Duration {
iter.fold(Duration::new(0, 0), |a, b| a + b)
}
}
#[stable(feature = "duration_sum", since = "1.16.0")]
impl<'a> Sum<&'a Duration> for Duration {
fn sum<I: Iterator<Item=&'a Duration>>(iter: I) -> Duration {
iter.fold(Duration::new(0, 0), |a, b| a + *b)
}
}
#[cfg(test)]
mod tests {
use super::Duration;