Skip to content

Commit 564bfc8

Browse files
committed
Implement AddAssign and SubAssign
1 parent 965ab29 commit 564bfc8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/duration.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//! Temporal quantification
1212
13-
use core::ops::{Add, Div, Mul, Neg, Sub};
13+
use core::ops::{Add, AddAssign, Div, Mul, Neg, Sub, SubAssign};
1414
use core::time::Duration as StdDuration;
1515
use core::{fmt, i64};
1616
#[cfg(any(feature = "std", test))]
@@ -380,6 +380,20 @@ impl Sub for Duration {
380380
}
381381
}
382382

383+
impl AddAssign for Duration {
384+
fn add_assign(&mut self, rhs: Duration) {
385+
let new = self.checked_add(&rhs).expect("`Duration + Duration` overflowed");
386+
*self = new;
387+
}
388+
}
389+
390+
impl SubAssign for Duration {
391+
fn sub_assign(&mut self, rhs: Duration) {
392+
let new = self.checked_sub(&rhs).expect("`Duration - Duration` overflowed");
393+
*self = new;
394+
}
395+
}
396+
383397
impl Mul<i32> for Duration {
384398
type Output = Duration;
385399

0 commit comments

Comments
 (0)