diff --git a/units/src/amount/result.rs b/units/src/amount/result.rs index b2091a1b5..724230833 100644 --- a/units/src/amount/result.rs +++ b/units/src/amount/result.rs @@ -129,7 +129,6 @@ crate::internal_macros::impl_op_for_references! { fn add(self, rhs: Amount) -> Self::Output { self.checked_add(rhs).valid_or_error() } } - impl ops::Add> for Amount { type Output = NumOpResult; @@ -141,7 +140,6 @@ crate::internal_macros::impl_op_for_references! { fn sub(self, rhs: Amount) -> Self::Output { self.checked_sub(rhs).valid_or_error() } } - impl ops::Sub> for Amount { type Output = NumOpResult; @@ -158,23 +156,39 @@ crate::internal_macros::impl_op_for_references! { fn mul(self, rhs: u64) -> Self::Output { self.checked_mul(rhs).valid_or_error() } } + impl ops::Mul for NumOpResult { + type Output = NumOpResult; + + fn mul(self, rhs: u64) -> Self::Output { self.and_then(|lhs| lhs * rhs) } + } + impl ops::Div for Amount { type Output = NumOpResult; fn div(self, rhs: u64) -> Self::Output { self.checked_div(rhs).valid_or_error() } } + impl ops::Div for NumOpResult { + type Output = NumOpResult; + + fn div(self, rhs: u64) -> Self::Output { self.and_then(|lhs| lhs / rhs) } + } + impl ops::Rem for Amount { type Output = NumOpResult; fn rem(self, modulus: u64) -> Self::Output { self.checked_rem(modulus).valid_or_error() } } + impl ops::Rem for NumOpResult { + type Output = NumOpResult; + + fn rem(self, modulus: u64) -> Self::Output { self.and_then(|lhs| lhs % modulus) } + } impl ops::Add for SignedAmount { type Output = NumOpResult; fn add(self, rhs: SignedAmount) -> Self::Output { self.checked_add(rhs).valid_or_error() } } - impl ops::Add> for SignedAmount { type Output = NumOpResult; @@ -202,16 +216,33 @@ crate::internal_macros::impl_op_for_references! { fn mul(self, rhs: i64) -> Self::Output { self.checked_mul(rhs).valid_or_error() } } + impl ops::Mul for NumOpResult { + type Output = NumOpResult; + + fn mul(self, rhs: i64) -> Self::Output { self.and_then(|lhs| lhs * rhs) } + } + impl ops::Div for SignedAmount { type Output = NumOpResult; fn div(self, rhs: i64) -> Self::Output { self.checked_div(rhs).valid_or_error() } } + impl ops::Div for NumOpResult { + type Output = NumOpResult; + + fn div(self, rhs: i64) -> Self::Output { self.and_then(|lhs| lhs / rhs) } + } + impl ops::Rem for SignedAmount { type Output = NumOpResult; fn rem(self, modulus: i64) -> Self::Output { self.checked_rem(modulus).valid_or_error() } } + impl ops::Rem for NumOpResult { + type Output = NumOpResult; + + fn rem(self, modulus: i64) -> Self::Output { self.and_then(|lhs| lhs % modulus) } + } impl ops::Add> for NumOpResult where