[][src]Struct rusty_money::Money

pub struct Money { /* 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().

Methods

impl Money[src]

pub fn new(amount: i64, currency: &'static Currency) -> Money[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_minor(amount: i64, currency: &'static Currency) -> Money[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: &'static Currency) -> Money[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: &'static Currency) -> Money[src]

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

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

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

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

pub fn from_string(
    amount: String,
    currency: String
) -> Result<Money, MoneyError>
[src]

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

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

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

Returns a reference to the Decimal amount.

pub fn currency(&self) -> &'static Currency[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>, 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>, 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[src]

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

Trait Implementations

impl Add<Money> for Money[src]

type Output = Money

The resulting type after applying the + operator.

impl AddAssign<Money> for Money[src]

impl Clone for Money[src]

impl Debug for Money[src]

impl Display for Money[src]

impl Div<Money> for isize[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<Money> for i8[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<Money> for i16[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<Money> for i32[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<Money> for i64[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<Money> for usize[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<Money> for u8[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<Money> for u16[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<Money> for u32[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<Money> for u64[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<i16> for Money[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<i32> for Money[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<i64> for Money[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<i8> for Money[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<isize> for Money[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<u16> for Money[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<u32> for Money[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<u64> for Money[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<u8> for Money[src]

type Output = Money

The resulting type after applying the / operator.

impl Div<usize> for Money[src]

type Output = Money

The resulting type after applying the / operator.

impl DivAssign<i16> for Money[src]

impl DivAssign<i32> for Money[src]

impl DivAssign<i64> for Money[src]

impl DivAssign<i8> for Money[src]

impl DivAssign<isize> for Money[src]

impl DivAssign<u16> for Money[src]

impl DivAssign<u32> for Money[src]

impl DivAssign<u64> for Money[src]

impl DivAssign<u8> for Money[src]

impl DivAssign<usize> for Money[src]

impl Eq for Money[src]

impl Mul<Money> for isize[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for i8[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for i16[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for i32[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for i64[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for usize[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for u8[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for u16[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for u32[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<Money> for u64[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<i16> for Money[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<i32> for Money[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<i64> for Money[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<i8> for Money[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<isize> for Money[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<u16> for Money[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<u32> for Money[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<u64> for Money[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<u8> for Money[src]

type Output = Money

The resulting type after applying the * operator.

impl Mul<usize> for Money[src]

type Output = Money

The resulting type after applying the * operator.

impl MulAssign<i16> for Money[src]

impl MulAssign<i32> for Money[src]

impl MulAssign<i64> for Money[src]

impl MulAssign<i8> for Money[src]

impl MulAssign<isize> for Money[src]

impl MulAssign<u16> for Money[src]

impl MulAssign<u32> for Money[src]

impl MulAssign<u64> for Money[src]

impl MulAssign<u8> for Money[src]

impl MulAssign<usize> for Money[src]

impl Ord for Money[src]

impl PartialEq<Money> for Money[src]

impl PartialOrd<Money> for Money[src]

impl StructuralEq for Money[src]

impl StructuralPartialEq for Money[src]

impl Sub<Money> for Money[src]

type Output = Money

The resulting type after applying the - operator.

impl SubAssign<Money> for Money[src]

Auto Trait Implementations

impl RefUnwindSafe for Money

impl Send for Money

impl Sync for Money

impl Unpin for Money

impl UnwindSafe for Money

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.