pub struct Money {
pub amount: Decimal,
pub currency: Currency,
}Expand description
An exact monetary amount, quantised to its currency’s minor unit.
Fields§
§amount: DecimalThe amount, exact, at currency.scale fractional digits.
currency: CurrencyImplementations§
Source§impl Money
impl Money
Sourcepub fn of(amount: Decimal, currency: Currency) -> Money
pub fn of(amount: Decimal, currency: Currency) -> Money
Build money, quantising the amount to the currency’s minor unit with banker’s rounding —
5 USD is stored as 5.00, 19.999 USD rounds to 20.00, 100 JPY stays 100.
Sourcepub fn add(&self, other: &Money) -> Option<Money>
pub fn add(&self, other: &Money) -> Option<Money>
Sum of two amounts in the same currency; None across currencies (no common meaning).
Sourcepub fn sub(&self, other: &Money) -> Option<Money>
pub fn sub(&self, other: &Money) -> Option<Money>
Difference of two amounts in the same currency; None across currencies.
Trait Implementations§
Source§impl PartialEq for Money
impl PartialEq for Money
impl Eq for Money
Auto Trait Implementations§
impl Freeze for Money
impl RefUnwindSafe for Money
impl Send for Money
impl Sync for Money
impl Unpin for Money
impl UnsafeUnpin for Money
impl UnwindSafe for Money
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more