diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2016-03-26 09:07:22 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2016-03-26 13:42:03 +0530 |
| commit | 023fae61751a572f722b59ef78862878580f204d (patch) | |
| tree | b4e820e9cfd17949b97a51516346ae20738a0cca /src/libstd/time | |
| parent | 515e87dde2f76477e1b324275ba4fef9a61ae5f1 (diff) | |
| parent | be87650f6310e31347a173787090dc89635fb57e (diff) | |
Rollup merge of #32448 - sfackler:time-augmented-assignment, r=alexcrichton
Add augmented assignment operator impls for time types r? @alexcrichton
Diffstat (limited to 'src/libstd/time')
| -rw-r--r-- | src/libstd/time/duration.rs | 30 | ||||
| -rw-r--r-- | src/libstd/time/mod.rs | 30 |
2 files changed, 58 insertions, 2 deletions
diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 7c3240b4a40..945eb6a42e5 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ops::{Add, Sub, Mul, Div}; +use ops::{Add, Sub, Mul, Div, AddAssign, SubAssign, MulAssign, DivAssign}; const NANOS_PER_SEC: u32 = 1_000_000_000; const NANOS_PER_MILLI: u32 = 1_000_000; @@ -105,6 +105,13 @@ impl Add for Duration { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl AddAssign for Duration { + fn add_assign(&mut self, rhs: Duration) { + *self = *self + rhs; + } +} + #[stable(feature = "duration", since = "1.3.0")] impl Sub for Duration { type Output = Duration; @@ -124,6 +131,13 @@ impl Sub for Duration { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl SubAssign for Duration { + fn sub_assign(&mut self, rhs: Duration) { + *self = *self - rhs; + } +} + #[stable(feature = "duration", since = "1.3.0")] impl Mul<u32> for Duration { type Output = Duration; @@ -141,6 +155,13 @@ impl Mul<u32> for Duration { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl MulAssign<u32> for Duration { + fn mul_assign(&mut self, rhs: u32) { + *self = *self * rhs; + } +} + #[stable(feature = "duration", since = "1.3.0")] impl Div<u32> for Duration { type Output = Duration; @@ -155,6 +176,13 @@ impl Div<u32> for Duration { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl DivAssign<u32> for Duration { + fn div_assign(&mut self, rhs: u32) { + *self = *self / rhs; + } +} + #[cfg(test)] mod tests { use super::Duration; diff --git a/src/libstd/time/mod.rs b/src/libstd/time/mod.rs index 0c32feebecb..bc50b0d3a70 100644 --- a/src/libstd/time/mod.rs +++ b/src/libstd/time/mod.rs @@ -24,7 +24,7 @@ use error::Error; use fmt; -use ops::{Add, Sub}; +use ops::{Add, Sub, AddAssign, SubAssign}; use sys::time; use sys_common::FromInner; @@ -172,6 +172,13 @@ impl Add<Duration> for Instant { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl AddAssign<Duration> for Instant { + fn add_assign(&mut self, other: Duration) { + *self = *self + other; + } +} + #[stable(feature = "time2", since = "1.8.0")] impl Sub<Duration> for Instant { type Output = Instant; @@ -181,6 +188,13 @@ impl Sub<Duration> for Instant { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl SubAssign<Duration> for Instant { + fn sub_assign(&mut self, other: Duration) { + *self = *self - other; + } +} + #[stable(feature = "time2", since = "1.8.0")] impl Sub<Instant> for Instant { type Output = Duration; @@ -254,6 +268,13 @@ impl Add<Duration> for SystemTime { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl AddAssign<Duration> for SystemTime { + fn add_assign(&mut self, other: Duration) { + *self = *self + other; + } +} + #[stable(feature = "time2", since = "1.8.0")] impl Sub<Duration> for SystemTime { type Output = SystemTime; @@ -263,6 +284,13 @@ impl Sub<Duration> for SystemTime { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl SubAssign<Duration> for SystemTime { + fn sub_assign(&mut self, other: Duration) { + *self = *self - other; + } +} + #[stable(feature = "time2", since = "1.8.0")] impl fmt::Debug for SystemTime { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
