Struct Money
pub struct Money { /* private fields */ }Expand description
A currency-safe money value.
Implementations§
§impl Money
impl Money
pub const fn new(amount: Amount, currency: CurrencyCode) -> Money
pub const fn new(amount: Amount, currency: CurrencyCode) -> Money
Creates money from an amount and currency.
pub const fn currency(&self) -> &CurrencyCode
pub const fn currency(&self) -> &CurrencyCode
Returns the currency.
pub fn checked_add(&self, other: &Money) -> Result<Money, MoneyError>
pub fn checked_add(&self, other: &Money) -> Result<Money, MoneyError>
Adds money values when their currencies match.
§Errors
Returns MoneyError::CurrencyMismatch when currencies differ and
MoneyError::Amount when amount addition fails.
pub fn checked_sub(&self, other: &Money) -> Result<Money, MoneyError>
pub fn checked_sub(&self, other: &Money) -> Result<Money, MoneyError>
Subtracts money values when their currencies match.
§Errors
Returns MoneyError::CurrencyMismatch when currencies differ and
MoneyError::Amount when amount subtraction fails.
Trait Implementations§
impl Eq for Money
impl StructuralPartialEq 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