diff --git a/src/duration.rs b/src/duration.rs index cd08ec8a6d..f426265fe6 100644 --- a/src/duration.rs +++ b/src/duration.rs @@ -10,7 +10,7 @@ //! Temporal quantification -use core::ops::{Add, Div, Mul, Neg, Sub}; +use core::ops::{Add, AddAssign, Div, Mul, Neg, Sub, SubAssign}; use core::time::Duration as StdDuration; use core::{fmt, i64}; #[cfg(any(feature = "std", test))] @@ -380,6 +380,20 @@ impl Sub for Duration { } } +impl AddAssign for Duration { + fn add_assign(&mut self, rhs: Duration) { + let new = self.checked_add(&rhs).expect("`Duration + Duration` overflowed"); + *self = new; + } +} + +impl SubAssign for Duration { + fn sub_assign(&mut self, rhs: Duration) { + let new = self.checked_sub(&rhs).expect("`Duration - Duration` overflowed"); + *self = new; + } +} + impl Mul for Duration { type Output = Duration;