Struct monies::Money[][src]

pub struct Money<'a, T: FormattableCurrency> { /* fields omitted */ }

Represents an amount of a given currency.

Money represents financial amounts through a Decimal (owned) and a Currency (refernce). Operations on Money objects always create new instances of Money, with the exception of round().

Implementations

impl<'a, T: FormattableCurrency> Money<'a, T>[src]

pub fn from_str(
    amount: &str,
    currency: &'a T
) -> Result<Money<'a, T>, MoneyError>
[src]

Creates a Money object given an amount string and a currency str.

Supports fuzzy amount strings like "100", "100.00" and "-100.00"

pub fn from_minor(amount: i64, currency: &'a T) -> Money<'a, T>[src]

Creates a Money object given an integer and a currency reference.

The integer represents minor units of the currency (e.g. 1000 -> 10.00 in USD )

pub fn from_major(amount: i64, currency: &'a T) -> Money<'a, T>[src]

Creates a Money object given an integer and a currency reference.

The integer represents major units of the currency (e.g. 1000 -> 1,000 in USD )

pub fn from_decimal(amount: Decimal, currency: &'a T) -> Money<'a, T>[src]

Creates a Money object given a decimal amount and a currency reference.

pub fn amount(&self) -> &Decimal[src]

Returns a reference to the Decimal amount.

pub fn currency(&self) -> &'a T[src]

Returns the Currency type.

pub fn is_zero(&self) -> bool[src]

Returns true if amount == 0.

pub fn is_positive(&self) -> bool[src]

Returns true if amount > 0.

pub fn is_negative(&self) -> bool[src]

Returns true if amount < 0.

pub fn allocate_to(&self, number: i32) -> Result<Vec<Money<'a, T>>, MoneyError>[src]

Divides money equally into n shares.

If the divison cannot be applied perfectly, it allocates the remainder to some of the shares.

pub fn allocate(
    &self,
    ratios: Vec<i32>
) -> Result<Vec<Money<'a, T>>, MoneyError>
[src]

Divides money into n shares according to a particular ratio.

If the divison cannot be applied perfectly, it allocates the remainder to some of the shares.

pub fn round(&self, digits: u32, strategy: Round) -> Money<'a, T>[src]

Returns a Money rounded to the specified number of minor units using the rounding strategy.

Trait Implementations

impl<'a, T: FormattableCurrency> Add<Money<'a, T>> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the + operator.

impl<'a, T: FormattableCurrency> AddAssign<Money<'a, T>> for Money<'a, T>[src]

impl<'a, T: Clone + FormattableCurrency> Clone for Money<'a, T>[src]

impl<'a, T: Debug + FormattableCurrency> Debug for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> Display for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> Div<Decimal> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the / operator.

impl<'a, T: FormattableCurrency> Div<i16> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the / operator.

impl<'a, T: FormattableCurrency> Div<i32> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the / operator.

impl<'a, T: FormattableCurrency> Div<i64> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the / operator.

impl<'a, T: FormattableCurrency> Div<i8> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the / operator.

impl<'a, T: FormattableCurrency> Div<isize> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the / operator.

impl<'a, T: FormattableCurrency> Div<u16> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the / operator.

impl<'a, T: FormattableCurrency> Div<u32> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the / operator.

impl<'a, T: FormattableCurrency> Div<u64> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the / operator.

impl<'a, T: FormattableCurrency> Div<u8> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the / operator.

impl<'a, T: FormattableCurrency> Div<usize> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the / operator.

impl<'a, T: FormattableCurrency> DivAssign<Decimal> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> DivAssign<i16> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> DivAssign<i32> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> DivAssign<i64> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> DivAssign<i8> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> DivAssign<isize> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> DivAssign<u16> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> DivAssign<u32> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> DivAssign<u64> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> DivAssign<u8> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> DivAssign<usize> for Money<'a, T>[src]

impl<'a, T: Eq + FormattableCurrency> Eq for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> Mul<Decimal> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the * operator.

impl<'a, T: FormattableCurrency> Mul<i16> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the * operator.

impl<'a, T: FormattableCurrency> Mul<i32> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the * operator.

impl<'a, T: FormattableCurrency> Mul<i64> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the * operator.

impl<'a, T: FormattableCurrency> Mul<i8> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the * operator.

impl<'a, T: FormattableCurrency> Mul<isize> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the * operator.

impl<'a, T: FormattableCurrency> Mul<u16> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the * operator.

impl<'a, T: FormattableCurrency> Mul<u32> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the * operator.

impl<'a, T: FormattableCurrency> Mul<u64> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the * operator.

impl<'a, T: FormattableCurrency> Mul<u8> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the * operator.

impl<'a, T: FormattableCurrency> Mul<usize> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the * operator.

impl<'a, T: FormattableCurrency> MulAssign<Decimal> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> MulAssign<i16> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> MulAssign<i32> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> MulAssign<i64> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> MulAssign<i8> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> MulAssign<isize> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> MulAssign<u16> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> MulAssign<u32> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> MulAssign<u64> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> MulAssign<u8> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> MulAssign<usize> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> Ord for Money<'a, T>[src]

impl<'a, T: PartialEq + FormattableCurrency> PartialEq<Money<'a, T>> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> PartialOrd<Money<'a, T>> for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> StructuralEq for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> StructuralPartialEq for Money<'a, T>[src]

impl<'a, T: FormattableCurrency> Sub<Money<'a, T>> for Money<'a, T>[src]

type Output = Money<'a, T>

The resulting type after applying the - operator.

impl<'a, T: FormattableCurrency> SubAssign<Money<'a, T>> for Money<'a, T>[src]

Auto Trait Implementations

impl<'a, T> RefUnwindSafe for Money<'a, T> where
    T: RefUnwindSafe
[src]

impl<'a, T> Send for Money<'a, T> where
    T: Sync
[src]

impl<'a, T> Sync for Money<'a, T> where
    T: Sync
[src]

impl<'a, T> Unpin for Money<'a, T>[src]

impl<'a, T> UnwindSafe for Money<'a, T> where
    T: RefUnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.