units: Implement ops for amount types

Use the shiny new ops macros to implement the full set of `Add`,
`AddAssign`, `Sub`, and `SubAssign` impls we require.
This commit is contained in:
Tobin C. Harding 2024-12-11 16:37:44 +11:00
parent 4a3aa4a08b
commit d88306fb68
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
2 changed files with 8 additions and 16 deletions

View File

@ -388,10 +388,8 @@ impl ops::Add for SignedAmount {
self.checked_add(rhs).expect("SignedAmount addition error")
}
}
impl ops::AddAssign for SignedAmount {
fn add_assign(&mut self, rhs: SignedAmount) { *self = *self + rhs }
}
crate::internal_macros::impl_add_for_references!(SignedAmount);
crate::internal_macros::impl_add_assign!(SignedAmount);
impl ops::Sub for SignedAmount {
type Output = SignedAmount;
@ -400,10 +398,8 @@ impl ops::Sub for SignedAmount {
self.checked_sub(rhs).expect("SignedAmount subtraction error")
}
}
impl ops::SubAssign for SignedAmount {
fn sub_assign(&mut self, rhs: SignedAmount) { *self = *self - rhs }
}
crate::internal_macros::impl_sub_for_references!(SignedAmount);
crate::internal_macros::impl_sub_assign!(SignedAmount);
impl ops::Rem<i64> for SignedAmount {
type Output = SignedAmount;

View File

@ -457,10 +457,8 @@ impl ops::Add for Amount {
self.checked_add(rhs).expect("Amount addition error")
}
}
impl ops::AddAssign for Amount {
fn add_assign(&mut self, rhs: Amount) { *self = *self + rhs }
}
crate::internal_macros::impl_add_for_references!(Amount);
crate::internal_macros::impl_add_assign!(Amount);
impl ops::Sub for Amount {
type Output = Amount;
@ -469,10 +467,8 @@ impl ops::Sub for Amount {
self.checked_sub(rhs).expect("Amount subtraction error")
}
}
impl ops::SubAssign for Amount {
fn sub_assign(&mut self, rhs: Amount) { *self = *self - rhs }
}
crate::internal_macros::impl_sub_for_references!(Amount);
crate::internal_macros::impl_sub_assign!(Amount);
impl ops::Rem<u64> for Amount {
type Output = Amount;