Skip to content

Commit

Permalink
Implement AddAssign and SubAssign
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jun 8, 2023
1 parent 965ab29 commit 564bfc8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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<i32> for Duration {
type Output = Duration;

Expand Down

0 comments on commit 564bfc8

Please sign in to comment.