diff options
| author | bors <bors@rust-lang.org> | 2017-01-19 01:09:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-01-19 01:09:46 +0000 |
| commit | 2263d1ba29f397d8e83989b7b478e39bf2b02180 (patch) | |
| tree | e1fc8464839453864e35f0400edde597473abbd9 /src/libstd | |
| parent | c8af93f0901c336e873ce18274026d0fd9bc7c1f (diff) | |
| parent | 03b66ead69b311dbe391c242b0a5924b0d8dac0f (diff) | |
| download | rust-2263d1ba29f397d8e83989b7b478e39bf2b02180.tar.gz rust-2263d1ba29f397d8e83989b7b478e39bf2b02180.zip | |
Auto merge of #38712 - clarcharr:duration_sum, r=sfackler
Sum for Duration Implemented the `Sum` trait for `Duration`. Seems reasonable.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/time/duration.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 162ce530f17..2c4e2bbff93 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -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; |
