]> git.lizzy.rs Git - rust.git/commitdiff
Add augmented assignment operator impls for time types
authorSteven Fackler <sfackler@gmail.com>
Wed, 23 Mar 2016 06:28:22 +0000 (23:28 -0700)
committerSteven Fackler <sfackler@gmail.com>
Wed, 23 Mar 2016 06:28:22 +0000 (23:28 -0700)
src/libstd/time/duration.rs
src/libstd/time/mod.rs

index 7c3240b4a40c4ac61ec5c8c64d4011dfc0062804..945eb6a42e5a7854ee6555b979934fe814081248 100644 (file)
@@ -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 @@ fn add(self, rhs: Duration) -> 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 @@ fn sub(self, rhs: Duration) -> 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 @@ fn mul(self, rhs: u32) -> 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 @@ fn div(self, rhs: u32) -> 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;
index aa0a843dc9a548763d6a713538e39fbe7659f9d3..414aeac2afe45d394285a59dd95997c6c219e33e 100644 (file)
@@ -14,7 +14,7 @@
 
 use error::Error;
 use fmt;
-use ops::{Add, Sub};
+use ops::{Add, Sub, AddAssign, SubAssign};
 use sys::time;
 use sys_common::FromInner;
 
@@ -122,6 +122,13 @@ fn add(self, other: Duration) -> 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;
@@ -131,6 +138,13 @@ fn sub(self, other: Duration) -> 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;
@@ -204,6 +218,13 @@ fn add(self, dur: Duration) -> 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;
@@ -213,6 +234,13 @@ fn sub(self, dur: Duration) -> 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 {