pub struct Money(/* private fields */);Expand description
Represents a monetary amount stored as cents (hundredths of the currency unit)
Using i64 cents avoids floating-point precision issues and supports amounts up to approximately $92 quadrillion (both positive and negative).
Implementations§
Source§impl Money
impl Money
Sourcepub const fn from_cents(cents: i64) -> Self
pub const fn from_cents(cents: i64) -> Self
Create a Money amount from cents
§Examples
use envelope_cli::models::Money;
let amount = Money::from_cents(1050); // $10.50Sourcepub const fn from_dollars_cents(dollars: i64, cents: i64) -> Self
pub const fn from_dollars_cents(dollars: i64, cents: i64) -> Self
Create a Money amount from dollars and cents
§Examples
use envelope_cli::models::Money;
let amount = Money::from_dollars_cents(10, 50); // $10.50Sourcepub const fn cents_part(&self) -> i64
pub const fn cents_part(&self) -> i64
Get the cents portion (0-99)
Sourcepub const fn is_positive(&self) -> bool
pub const fn is_positive(&self) -> bool
Check if the amount is positive
Sourcepub const fn is_negative(&self) -> bool
pub const fn is_negative(&self) -> bool
Check if the amount is negative
Sourcepub fn parse(s: &str) -> Result<Self, MoneyParseError>
pub fn parse(s: &str) -> Result<Self, MoneyParseError>
Parse a money amount from a string
Accepts formats: “10.50”, “-10.50”, “$10.50”, “10”, “1050” (cents)
Sourcepub fn format_with_symbol(&self, symbol: &str) -> String
pub fn format_with_symbol(&self, symbol: &str) -> String
Format with a currency symbol
Trait Implementations§
Source§impl AddAssign for Money
impl AddAssign for Money
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+= operation. Read moreSource§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
Source§impl SubAssign for Money
impl SubAssign for Money
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs the
-= operation. Read moreimpl 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 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read more