Struct monies::Money [−][src]
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]
amount: &str,
currency: &'a T
) -> Result<Money<'a, T>, MoneyError>
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]
&self,
ratios: Vec<i32>
) -> Result<Vec<Money<'a, T>>, MoneyError>
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.
fn add(self, other: Money<'a, T>) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> AddAssign<Money<'a, T>> for Money<'a, T>
[src]
fn add_assign(&mut self, other: Self)
[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.
fn div(self, rhs: Decimal) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Div<i16> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the /
operator.
fn div(self, rhs: i16) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Div<i32> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the /
operator.
fn div(self, rhs: i32) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Div<i64> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the /
operator.
fn div(self, rhs: i64) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Div<i8> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the /
operator.
fn div(self, rhs: i8) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Div<isize> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the /
operator.
fn div(self, rhs: isize) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Div<u16> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the /
operator.
fn div(self, rhs: u16) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Div<u32> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the /
operator.
fn div(self, rhs: u32) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Div<u64> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the /
operator.
fn div(self, rhs: u64) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Div<u8> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the /
operator.
fn div(self, rhs: u8) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Div<usize> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the /
operator.
fn div(self, rhs: usize) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> DivAssign<Decimal> for Money<'a, T>
[src]
fn div_assign(&mut self, rhs: Decimal)
[src]
impl<'a, T: FormattableCurrency> DivAssign<i16> for Money<'a, T>
[src]
fn div_assign(&mut self, rhs: i16)
[src]
impl<'a, T: FormattableCurrency> DivAssign<i32> for Money<'a, T>
[src]
fn div_assign(&mut self, rhs: i32)
[src]
impl<'a, T: FormattableCurrency> DivAssign<i64> for Money<'a, T>
[src]
fn div_assign(&mut self, rhs: i64)
[src]
impl<'a, T: FormattableCurrency> DivAssign<i8> for Money<'a, T>
[src]
fn div_assign(&mut self, rhs: i8)
[src]
impl<'a, T: FormattableCurrency> DivAssign<isize> for Money<'a, T>
[src]
fn div_assign(&mut self, rhs: isize)
[src]
impl<'a, T: FormattableCurrency> DivAssign<u16> for Money<'a, T>
[src]
fn div_assign(&mut self, rhs: u16)
[src]
impl<'a, T: FormattableCurrency> DivAssign<u32> for Money<'a, T>
[src]
fn div_assign(&mut self, rhs: u32)
[src]
impl<'a, T: FormattableCurrency> DivAssign<u64> for Money<'a, T>
[src]
fn div_assign(&mut self, rhs: u64)
[src]
impl<'a, T: FormattableCurrency> DivAssign<u8> for Money<'a, T>
[src]
fn div_assign(&mut self, rhs: u8)
[src]
impl<'a, T: FormattableCurrency> DivAssign<usize> for Money<'a, T>
[src]
fn div_assign(&mut self, rhs: usize)
[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.
fn mul(self, rhs: Decimal) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Mul<i16> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the *
operator.
fn mul(self, rhs: i16) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Mul<i32> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the *
operator.
fn mul(self, rhs: i32) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Mul<i64> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the *
operator.
fn mul(self, rhs: i64) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Mul<i8> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the *
operator.
fn mul(self, rhs: i8) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Mul<isize> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the *
operator.
fn mul(self, rhs: isize) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Mul<u16> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the *
operator.
fn mul(self, rhs: u16) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Mul<u32> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the *
operator.
fn mul(self, rhs: u32) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Mul<u64> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the *
operator.
fn mul(self, rhs: u64) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Mul<u8> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the *
operator.
fn mul(self, rhs: u8) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> Mul<usize> for Money<'a, T>
[src]
type Output = Money<'a, T>
The resulting type after applying the *
operator.
fn mul(self, rhs: usize) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> MulAssign<Decimal> for Money<'a, T>
[src]
fn mul_assign(&mut self, rhs: Decimal)
[src]
impl<'a, T: FormattableCurrency> MulAssign<i16> for Money<'a, T>
[src]
fn mul_assign(&mut self, rhs: i16)
[src]
impl<'a, T: FormattableCurrency> MulAssign<i32> for Money<'a, T>
[src]
fn mul_assign(&mut self, rhs: i32)
[src]
impl<'a, T: FormattableCurrency> MulAssign<i64> for Money<'a, T>
[src]
fn mul_assign(&mut self, rhs: i64)
[src]
impl<'a, T: FormattableCurrency> MulAssign<i8> for Money<'a, T>
[src]
fn mul_assign(&mut self, rhs: i8)
[src]
impl<'a, T: FormattableCurrency> MulAssign<isize> for Money<'a, T>
[src]
fn mul_assign(&mut self, rhs: isize)
[src]
impl<'a, T: FormattableCurrency> MulAssign<u16> for Money<'a, T>
[src]
fn mul_assign(&mut self, rhs: u16)
[src]
impl<'a, T: FormattableCurrency> MulAssign<u32> for Money<'a, T>
[src]
fn mul_assign(&mut self, rhs: u32)
[src]
impl<'a, T: FormattableCurrency> MulAssign<u64> for Money<'a, T>
[src]
fn mul_assign(&mut self, rhs: u64)
[src]
impl<'a, T: FormattableCurrency> MulAssign<u8> for Money<'a, T>
[src]
fn mul_assign(&mut self, rhs: u8)
[src]
impl<'a, T: FormattableCurrency> MulAssign<usize> for Money<'a, T>
[src]
fn mul_assign(&mut self, rhs: usize)
[src]
impl<'a, T: FormattableCurrency> Ord for Money<'a, T>
[src]
fn cmp(&self, other: &Money<'a, T>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[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]
fn partial_cmp(&self, other: &Money<'a, T>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[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.
fn sub(self, other: Money<'a, T>) -> Money<'a, T>
[src]
impl<'a, T: FormattableCurrency> SubAssign<Money<'a, T>> for Money<'a, T>
[src]
fn sub_assign(&mut self, other: Self)
[src]
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for Money<'a, T> where
T: RefUnwindSafe,
[src]
T: RefUnwindSafe,
impl<'a, T> Send for Money<'a, T> where
T: Sync,
[src]
T: Sync,
impl<'a, T> Sync for Money<'a, T> where
T: Sync,
[src]
T: Sync,
impl<'a, T> Unpin for Money<'a, T>
[src]
impl<'a, T> UnwindSafe for Money<'a, T> where
T: RefUnwindSafe,
[src]
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,