Merge rust-bitcoin/rust-bitcoin#2471: units: Implement ops::Neg for SignedAmount

7d538c830d units: Implement ops::Neg for SignedAmount (Tobin C. Harding)

Pull request description:

  Its useful to be able to do `let x = -btc_amount;`

  Implement `core::ops::Neg for SignedAmount`, returning a `SignedAmount`.

  Fix: #2470

ACKs for top commit:
  Kixunil:
    ACK 7d538c830d
  apoelstra:
    ACK 7d538c830d

Tree-SHA512: 168808c34513ccf7773ba03abe9375f3bed0fa92b320af5538620142552fecda671b75295a8ba6720f1aead3c722869d8dcffeeaab565c370973d2bcb8b59d1b
This commit is contained in:
Andrew Poelstra 2024-02-12 19:45:35 +00:00
commit bac493153a
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 6 additions and 0 deletions

View File

@ -1328,6 +1328,12 @@ impl ops::DivAssign<i64> 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;