pub struct Money { /* private fields */ }Expand description
Money amount in the smallest currency unit (cents for USD).
Implementations§
Source§impl Money
impl Money
Sourcepub const fn from_cents(cents: u64, currency: Currency) -> Self
pub const fn from_cents(cents: u64, currency: Currency) -> Self
Create from cents.
Sourcepub const fn from_dollars(dollars: u64, currency: Currency) -> Self
pub const fn from_dollars(dollars: u64, currency: Currency) -> Self
Create from dollars (or major currency unit).
Sourcepub const fn usd_dollars(dollars: u64) -> Self
pub const fn usd_dollars(dollars: u64) -> Self
USD from dollars.
pub const fn cents(&self) -> u64
pub const fn currency(&self) -> Currency
Sourcepub fn as_dollars_f64(&self) -> f64
pub fn as_dollars_f64(&self) -> f64
Convert to f64 dollars for display. NOT for calculations.
Sourcepub const fn percent_bps(self, bps: u64) -> Self
pub const fn percent_bps(self, bps: u64) -> Self
Apply a percentage (basis points: 100 = 1%, 10000 = 100%). Commission calculation: amount.percent_bps(800) = 8%.
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
Source§impl Ord for Money
impl Ord for Money
Source§impl PartialOrd for Money
impl PartialOrd for Money
impl Copy for Money
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