[−][src]Struct monet::Money
A struct containing an amount
of money having a certain currency_code
.
Note that amount
contains fractions of a unit. See AMOUNT_UNIT
.
Examples
use monet::{Money, CurrencyAmount, Rates, Operation}; use std::convert::TryInto; // Custom rates. let map = vec![("USD", 1_000_000)].into_iter() .map(|(code, worth)| (code.try_into().unwrap(), worth.into())) .collect(); let rates = Rates::with_rates(map); let money_owned = Money::with_str_code(CurrencyAmount::with_unit(2), "USD").unwrap(); let money_paid = Money::with_str_code(CurrencyAmount::with_unit(1), "USD").unwrap(); let remaining = (money_owned - money_paid).execute(&rates); assert_eq!(remaining, Money::with_str_code(CurrencyAmount::with_unit(1), "USD"));
Fields
amount: CurrencyAmount
currency_code: CurrencyCode
Methods
impl Money
[src]
pub fn new(amount: CurrencyAmount, currency_code: CurrencyCode) -> Self
[src]
pub fn into_code(self, code: CurrencyCode, rates: &Rates) -> Option<Money>
[src]
pub fn with_str_code(
amount: CurrencyAmount,
currency_code: &str
) -> Option<Money>
[src]
amount: CurrencyAmount,
currency_code: &str
) -> Option<Money>
Creates Money
with given amount and code. Returns None
if the given code is not three characters long.
Trait Implementations
impl Operation for Money
[src]
impl Clone for Money
[src]
impl Copy for Money
[src]
impl Default for Money
[src]
impl Eq for Money
[src]
impl PartialEq<Money> for Money
[src]
impl Display for Money
[src]
Money can be displayed in the following format: 12.10 CHF
.
Default precision is dependent on the currency code (see ISO 4217 exponent).
A custom precision in range 0..=6
can be provided like this:
use monet::Money; let money = Money::with_str_code(12_100_000.into(), "CHF").unwrap(); assert_eq!( &format!("{}", money), "12.10 CHF" ); assert_eq!( &format!("{:.2}", money), "12.10 CHF" ); assert_eq!( &format!("{:.6}", money), "12.100000 CHF" ); // Note: the formatted version has lost a decimal due to the // lower precision assert_eq!( &format!("{:.0}", money), "12 CHF" );
impl Debug for Money
[src]
impl Div<Exponent> for Money
[src]
type Output = Div<Self>
The resulting type after applying the /
operator.
fn div(self, exp: Exponent) -> Self::Output
[src]
impl<O: Operation> Sub<O> for Money
[src]
type Output = Sub<Self, O>
The resulting type after applying the -
operator.
fn sub(self, other: O) -> Self::Output
[src]
impl<O: Operation> Add<O> for Money
[src]
type Output = Add<Self, O>
The resulting type after applying the +
operator.
fn add(self, other: O) -> Self::Output
[src]
impl Mul<Exponent> for Money
[src]
type Output = Mul<Self>
The resulting type after applying the *
operator.
fn mul(self, exp: Exponent) -> Self::Output
[src]
impl StructuralPartialEq for Money
[src]
impl StructuralEq for Money
[src]
Auto Trait Implementations
impl Send for Money
impl Sync for Money
impl Unpin for Money
impl UnwindSafe for Money
impl RefUnwindSafe for Money
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,