Auto merge of #38712 - clarcharr:duration_sum, r=sfackler
Sum for Duration Implemented the `Sum` trait for `Duration`. Seems reasonable.
This commit is contained in:
commit
2263d1ba29
@ -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 @@ fn div_assign(&mut self, rhs: u32) {
|
||||
}
|
||||
}
|
||||
|
||||
#[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;
|
||||
|
Loading…
Reference in New Issue
Block a user