pub struct CurrencyAmount {
pub amount: Decimal,
pub currency: Currency,
}Expand description
A monetary amount with a currency.
Fields§
§amount: DecimalThe monetary amount.
currency: CurrencyThe currency.
Implementations§
Source§impl CurrencyAmount
impl CurrencyAmount
Sourcepub fn new(amount: impl Into<Decimal>, currency: Currency) -> CurrencyAmount
pub fn new(amount: impl Into<Decimal>, currency: Currency) -> CurrencyAmount
Creates a new CurrencyAmount from an integer value.
Sourcepub fn from_str_values(
amount: &str,
currency: Currency,
) -> Result<CurrencyAmount, MoneyError>
pub fn from_str_values( amount: &str, currency: Currency, ) -> Result<CurrencyAmount, MoneyError>
Creates a new CurrencyAmount from a string representation.
§Arguments
amount- A string like"19.99"currency- The currency code like"USD"
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 abs(&self) -> CurrencyAmount
pub fn abs(&self) -> CurrencyAmount
Returns the absolute value of the amount.
Sourcepub fn negate(&self) -> CurrencyAmount
pub fn negate(&self) -> CurrencyAmount
Negates the amount.
Sourcepub fn round(&self) -> CurrencyAmount
pub fn round(&self) -> CurrencyAmount
Rounds the amount to the currency’s decimal places.
Sourcepub fn round_to(&self, decimal_places: u32) -> CurrencyAmount
pub fn round_to(&self, decimal_places: u32) -> CurrencyAmount
Rounds the amount to the specified number of decimal places.
Trait Implementations§
Source§impl Add for CurrencyAmount
impl Add for CurrencyAmount
Source§type Output = Result<CurrencyAmount, MoneyError>
type Output = Result<CurrencyAmount, MoneyError>
The resulting type after applying the
+ operator.Source§fn add(self, rhs: CurrencyAmount) -> <CurrencyAmount as Add>::Output
fn add(self, rhs: CurrencyAmount) -> <CurrencyAmount as Add>::Output
Performs the
+ operation. Read moreSource§impl Clone for CurrencyAmount
impl Clone for CurrencyAmount
Source§fn clone(&self) -> CurrencyAmount
fn clone(&self) -> CurrencyAmount
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CurrencyAmount
impl Debug for CurrencyAmount
Source§impl<'de> Deserialize<'de> for CurrencyAmount
impl<'de> Deserialize<'de> for CurrencyAmount
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CurrencyAmount, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CurrencyAmount, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for CurrencyAmount
impl Display for CurrencyAmount
impl Eq for CurrencyAmount
Source§impl PartialEq for CurrencyAmount
impl PartialEq for CurrencyAmount
Source§impl Serialize for CurrencyAmount
impl Serialize for CurrencyAmount
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl StructuralPartialEq for CurrencyAmount
Source§impl Sub for CurrencyAmount
impl Sub for CurrencyAmount
Source§type Output = Result<CurrencyAmount, MoneyError>
type Output = Result<CurrencyAmount, MoneyError>
The resulting type after applying the
- operator.Source§fn sub(self, rhs: CurrencyAmount) -> <CurrencyAmount as Sub>::Output
fn sub(self, rhs: CurrencyAmount) -> <CurrencyAmount as Sub>::Output
Performs the
- operation. Read moreAuto Trait Implementations§
impl Freeze for CurrencyAmount
impl RefUnwindSafe for CurrencyAmount
impl Send for CurrencyAmount
impl Sync for CurrencyAmount
impl Unpin for CurrencyAmount
impl UnsafeUnpin for CurrencyAmount
impl UnwindSafe for CurrencyAmount
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