core: add arithmetic operators for 'TxAmount'

This commit is contained in:
Bruno BELANYI 2022-08-23 12:18:48 +02:00
parent 963748e1d9
commit 19b5f3390d
1 changed files with 36 additions and 0 deletions

View File

@ -30,3 +30,39 @@ pub struct TxAmount(#[serde_as(as = "DisplayFromStr")] pub Decimal);
impl TxAmount {
pub const ZERO: Self = Self(Dec!(0));
}
impl std::ops::Add<TxAmount> for TxAmount {
type Output = Self;
fn add(self, rhs: TxAmount) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl std::ops::AddAssign<TxAmount> for TxAmount {
fn add_assign(&mut self, rhs: TxAmount) {
*self = *self + rhs;
}
}
impl std::ops::Sub<TxAmount> for TxAmount {
type Output = Self;
fn sub(self, rhs: TxAmount) -> Self::Output {
Self(self.0 - rhs.0)
}
}
impl std::ops::SubAssign<TxAmount> for TxAmount {
fn sub_assign(&mut self, rhs: TxAmount) {
*self = *self - rhs;
}
}
impl std::ops::Neg for TxAmount {
type Output = Self;
fn neg(self) -> Self::Output {
Self(-self.0)
}
}