pub struct Money { /* private fields */ }Expand description
Represents a monetary amount with an associated currency.
Implementations§
Source§impl Money
impl Money
Sourcepub fn zero(currency: impl Into<String>) -> Self
pub fn zero(currency: impl Into<String>) -> Self
Creates a zero amount in the specified currency.
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Returns true if the amount is positive.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true if the amount is negative.
Sourcepub fn checked_add(&self, other: &Self) -> Option<Self>
pub fn checked_add(&self, other: &Self) -> Option<Self>
Adds two Money values if they have the same currency. Returns None if currencies don’t match.
Sourcepub fn checked_sub(&self, other: &Self) -> Option<Self>
pub fn checked_sub(&self, other: &Self) -> Option<Self>
Subtracts two Money values if they have the same currency. Returns None if currencies don’t match.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Money
impl<'de> Deserialize<'de> for Money
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Money
impl StructuralPartialEq for Money
Auto Trait Implementations§
impl Forget for Money
impl Freeze for Money
impl Move 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