diff --git a/crates/cdk/src/amount.rs b/crates/cdk/src/amount.rs index 35442721..19e69c97 100644 --- a/crates/cdk/src/amount.rs +++ b/crates/cdk/src/amount.rs @@ -87,18 +87,36 @@ impl Default for &Amount { } } +impl fmt::Display for Amount { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + impl From for Amount { fn from(value: u64) -> Self { Self(value) } } +impl From<&u64> for Amount { + fn from(value: &u64) -> Self { + Self(*value) + } +} + impl From for u64 { fn from(value: Amount) -> Self { value.0 } } +impl AsRef for Amount { + fn as_ref(&self) -> &u64 { + &self.0 + } +} + impl std::ops::Add for Amount { type Output = Amount; @@ -121,9 +139,25 @@ impl std::ops::Sub for Amount { } } -impl fmt::Display for Amount { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.0) +impl std::ops::SubAssign for Amount { + fn sub_assign(&mut self, other: Self) { + self.0 -= other.0; + } +} + +impl std::ops::Mul for Amount { + type Output = Self; + + fn mul(self, other: Self) -> Self::Output { + Amount(self.0 * other.0) + } +} + +impl std::ops::Div for Amount { + type Output = Self; + + fn div(self, other: Self) -> Self::Output { + Amount(self.0 / other.0) } }