Struct steel_cent::SmallMoney
[−]
[src]
pub struct SmallMoney { pub currency: Currency, // some fields omitted }
A 64-bit-sized, signed amount of money in a certain currency.
The range of supported values is small enough to be inappropriate for some practical
applications. See max
and min
below.
assert_eq!(8, std::mem::size_of::<SmallMoney>());Run
Examples
let price = SmallMoney::of_major_minor(USD, 19, 95); let shipping_and_handling = SmallMoney::of_major(USD, 10); let convenience_charge = SmallMoney::of_major(USD, 6); let discount: f64 = 1.0 - 0.2; // 20% off let discounted_price = price * discount; let fees = shipping_and_handling + convenience_charge; let total = discounted_price + fees; println!("price: {:?}, discounted_price: {:?}", price, discounted_price); assert_eq!(SmallMoney::of_minor(USD, 1596), discounted_price); assert_eq!(SmallMoney::of_minor(USD, 3196), total); assert_eq!((price * discount) + shipping_and_handling + convenience_charge, total);Run
Fields
currency: Currency
Methods
impl SmallMoney
[src]
fn of_minor(currency: Currency, amount_minor: i32) -> Self
Creates a SmallMoney from its "minor" unit (e.g. US cents to USD).
fn of_major(currency: Currency, amount_major: i32) -> Self
Creates a SmallMoney from its "major" unit (e.g. US dollars to USD).
fn of_major_minor(currency: Currency, amount_major: i32, amount_minor: i32) -> Self
fn major_part(&self) -> i32
fn minor_part(&self) -> i32
fn min(currency: Currency) -> SmallMoney
assert_eq!(SmallMoney::of_major_minor(USD, -21_474_836, -48), SmallMoney::min(USD));Run
fn max(currency: Currency) -> SmallMoney
assert_eq!(SmallMoney::of_major_minor(USD, 21_474_836, 47), SmallMoney::max(USD));Run
Trait Implementations
impl Debug for SmallMoney
[src]
impl PartialEq for SmallMoney
[src]
fn eq(&self, __arg_0: &SmallMoney) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &SmallMoney) -> bool
This method tests for !=
.
impl Eq for SmallMoney
[src]
impl Copy for SmallMoney
[src]
impl Clone for SmallMoney
[src]
fn clone(&self) -> SmallMoney
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl FormattableMoney for SmallMoney
[src]
fn unformatted_minor_amount(&self) -> String
fn currency(&self) -> Currency
impl Add for SmallMoney
[src]
type Output = SmallMoney
The resulting type after applying the +
operator
fn add(self, other: SmallMoney) -> SmallMoney
The method for the +
operator
impl Sub for SmallMoney
[src]
type Output = SmallMoney
The resulting type after applying the -
operator
fn sub(self, other: SmallMoney) -> SmallMoney
The method for the -
operator
impl Mul<i32> for SmallMoney
[src]
type Output = SmallMoney
The resulting type after applying the *
operator
fn mul(self, n: i32) -> SmallMoney
The method for the *
operator
impl Mul<f64> for SmallMoney
[src]
type Output = SmallMoney
The resulting type after applying the *
operator
fn mul(self, n: f64) -> SmallMoney
The method for the *
operator
impl Div<i32> for SmallMoney
[src]
type Output = SmallMoney
The resulting type after applying the /
operator
fn div(self, n: i32) -> SmallMoney
The method for the /
operator
impl Rem<i32> for SmallMoney
[src]
type Output = SmallMoney
The resulting type after applying the %
operator
fn rem(self, n: i32) -> SmallMoney
The method for the %
operator
impl<'a> Add<SmallMoney> for &'a SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the +
operator
fn add(self, other: SmallMoney) -> SmallMoney::Output
The method for the +
operator
impl<'a> Add<&'a SmallMoney> for SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the +
operator
fn add(self, other: &'a SmallMoney) -> SmallMoney::Output
The method for the +
operator
impl<'a, 'b> Add<&'a SmallMoney> for &'b SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the +
operator
fn add(self, other: &'a SmallMoney) -> SmallMoney::Output
The method for the +
operator
impl<'a> Sub<SmallMoney> for &'a SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the -
operator
fn sub(self, other: SmallMoney) -> SmallMoney::Output
The method for the -
operator
impl<'a> Sub<&'a SmallMoney> for SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the -
operator
fn sub(self, other: &'a SmallMoney) -> SmallMoney::Output
The method for the -
operator
impl<'a, 'b> Sub<&'a SmallMoney> for &'b SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the -
operator
fn sub(self, other: &'a SmallMoney) -> SmallMoney::Output
The method for the -
operator
impl<'a> Mul<i32> for &'a SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the *
operator
fn mul(self, other: i32) -> SmallMoney::Output
The method for the *
operator
impl<'a> Mul<&'a i32> for SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the *
operator
fn mul(self, other: &'a i32) -> SmallMoney::Output
The method for the *
operator
impl<'a, 'b> Mul<&'a i32> for &'b SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the *
operator
fn mul(self, other: &'a i32) -> SmallMoney::Output
The method for the *
operator
impl<'a> Mul<f64> for &'a SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the *
operator
fn mul(self, other: f64) -> SmallMoney::Output
The method for the *
operator
impl<'a> Mul<&'a f64> for SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the *
operator
fn mul(self, other: &'a f64) -> SmallMoney::Output
The method for the *
operator
impl<'a, 'b> Mul<&'a f64> for &'b SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the *
operator
fn mul(self, other: &'a f64) -> SmallMoney::Output
The method for the *
operator
impl<'a> Div<i32> for &'a SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the /
operator
fn div(self, other: i32) -> SmallMoney::Output
The method for the /
operator
impl<'a> Div<&'a i32> for SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the /
operator
fn div(self, other: &'a i32) -> SmallMoney::Output
The method for the /
operator
impl<'a, 'b> Div<&'a i32> for &'b SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the /
operator
fn div(self, other: &'a i32) -> SmallMoney::Output
The method for the /
operator
impl<'a> Rem<i32> for &'a SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the %
operator
fn rem(self, other: i32) -> SmallMoney::Output
The method for the %
operator
impl<'a> Rem<&'a i32> for SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the %
operator
fn rem(self, other: &'a i32) -> SmallMoney::Output
The method for the %
operator
impl<'a, 'b> Rem<&'a i32> for &'b SmallMoney
[src]
type Output = SmallMoney::Output
The resulting type after applying the %
operator
fn rem(self, other: &'a i32) -> SmallMoney::Output
The method for the %
operator
impl Neg for SmallMoney
[src]
type Output = SmallMoney
The resulting type after applying the -
operator
fn neg(self) -> SmallMoney
The method for the unary -
operator
impl<'a> Neg for &'a SmallMoney
[src]
type Output = SmallMoney
The resulting type after applying the -
operator
fn neg(self) -> SmallMoney
The method for the unary -
operator
impl PartialOrd for SmallMoney
[src]
fn partial_cmp(&self, other: &SmallMoney) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more