From 7d538c830d301c97a56a133cec0beeeffe1be4af Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 12 Feb 2024 13:04:26 +1100 Subject: [PATCH] units: Implement ops::Neg for SignedAmount Its useful to be able to do `let x = -btc_amount;` Implement `core::ops::Neg for SignedAmount`, returning a `SignedAmount`. Fix: #2470 --- units/src/amount.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/units/src/amount.rs b/units/src/amount.rs index 92f6ef76..87369d02 100644 --- a/units/src/amount.rs +++ b/units/src/amount.rs @@ -1328,6 +1328,12 @@ impl ops::DivAssign for SignedAmount { fn div_assign(&mut self, rhs: i64) { *self = *self / rhs } } +impl ops::Neg for SignedAmount { + type Output = Self; + + fn neg(self) -> Self::Output { Self(self.0.neg()) } +} + impl FromStr for SignedAmount { type Err = ParseError;