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

Methods

impl SmallMoney
[src]

Creates a SmallMoney from its "minor" unit (e.g. US cents to USD).

Creates a SmallMoney from its "major" unit (e.g. US dollars to USD).

assert_eq!(SmallMoney::of_major_minor(USD, -21_474_836, -48), SmallMoney::min(USD));Run

assert_eq!(SmallMoney::of_major_minor(USD, 21_474_836, 47), SmallMoney::max(USD));Run

Trait Implementations

impl Debug for SmallMoney
[src]

Formats the value using the given formatter.

impl PartialEq for SmallMoney
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for SmallMoney
[src]

impl Copy for SmallMoney
[src]

impl Clone for SmallMoney
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl FormattableMoney for SmallMoney
[src]

impl Add for SmallMoney
[src]

The resulting type after applying the + operator

The method for the + operator

impl Sub for SmallMoney
[src]

The resulting type after applying the - operator

The method for the - operator

impl Mul<i32> for SmallMoney
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<f64> for SmallMoney
[src]

The resulting type after applying the * operator

The method for the * operator

impl Div<i32> for SmallMoney
[src]

The resulting type after applying the / operator

The method for the / operator

impl Rem<i32> for SmallMoney
[src]

The resulting type after applying the % operator

The method for the % operator

impl<'a> Add<SmallMoney> for &'a SmallMoney
[src]

The resulting type after applying the + operator

The method for the + operator

impl<'a> Add<&'a SmallMoney> for SmallMoney
[src]

The resulting type after applying the + operator

The method for the + operator

impl<'a, 'b> Add<&'a SmallMoney> for &'b SmallMoney
[src]

The resulting type after applying the + operator

The method for the + operator

impl<'a> Sub<SmallMoney> for &'a SmallMoney
[src]

The resulting type after applying the - operator

The method for the - operator

impl<'a> Sub<&'a SmallMoney> for SmallMoney
[src]

The resulting type after applying the - operator

The method for the - operator

impl<'a, 'b> Sub<&'a SmallMoney> for &'b SmallMoney
[src]

The resulting type after applying the - operator

The method for the - operator

impl<'a> Mul<i32> for &'a SmallMoney
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a i32> for SmallMoney
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'a i32> for &'b SmallMoney
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<f64> for &'a SmallMoney
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a f64> for SmallMoney
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'a f64> for &'b SmallMoney
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Div<i32> for &'a SmallMoney
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a i32> for SmallMoney
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'a i32> for &'b SmallMoney
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Rem<i32> for &'a SmallMoney
[src]

The resulting type after applying the % operator

The method for the % operator

impl<'a> Rem<&'a i32> for SmallMoney
[src]

The resulting type after applying the % operator

The method for the % operator

impl<'a, 'b> Rem<&'a i32> for &'b SmallMoney
[src]

The resulting type after applying the % operator

The method for the % operator

impl Neg for SmallMoney
[src]

The resulting type after applying the - operator

The method for the unary - operator

impl<'a> Neg for &'a SmallMoney
[src]

The resulting type after applying the - operator

The method for the unary - operator

impl PartialOrd for SmallMoney
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more