Struct steel_cent::Money [] [src]

pub struct Money {
    pub currency: Currency,
    // some fields omitted
}

A signed amount of money in a certain currency.

assert_eq!(16, std::mem::size_of::<Money>());Run

Examples

let price = Money::of_major_minor(USD, 19, 95);
let shipping_and_handling = Money::of_major(USD, 10);
let convenience_charge = Money::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!(Money::of_minor(USD, 1596), discounted_price);
assert_eq!(Money::of_minor(USD, 3196), total);
assert_eq!((price * discount) + shipping_and_handling + convenience_charge, total);Run

Fields

Methods

impl Money
[src]

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

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

assert_eq!(Money::of_major_minor(USD, -92_233_720_368_547_758, -08), Money::min(USD));Run

assert_eq!(Money::of_major_minor(USD, 92_233_720_368_547_758, 07), Money::max(USD));Run

Trait Implementations

impl Debug for Money
[src]

Formats the value using the given formatter.

impl PartialEq for Money
[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 Money
[src]

impl Copy for Money
[src]

impl Clone for Money
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl FormattableMoney for Money
[src]

impl Add for Money
[src]

let one = Money::of_major(USD, 1);
assert_eq!(Money::of_major(USD, 2), one.clone() + one);Run

Attempting to add moneys of different currencies will panic.

Money::of_major(USD, 1) + Money::of_major(JPY, 1); // panics!Run

The resulting type after applying the + operator

The method for the + operator

impl<'b> Add<&'b Money> for Money
[src]

let one = Money::of_major(USD, 1);
assert_eq!(Money::of_major(USD, 2), one.clone() + &one);Run

Attempting to add moneys of different currencies will panic.

Money::of_major(USD, 1) + &Money::of_major(JPY, 1); // panics!Run

The resulting type after applying the + operator

The method for the + operator

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

let one = Money::of_major(USD, 1);
assert_eq!(Money::of_major(USD, 2), &one + one.clone());Run

Attempting to add moneys of different currencies will panic.

&Money::of_major(USD, 1) + Money::of_major(JPY, 1); // panics!Run

The resulting type after applying the + operator

The method for the + operator

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

let one = Money::of_major(USD, 1);
assert_eq!(Money::of_major(USD, 2), &one + &one);Run

Attempting to add moneys of different currencies will panic.

&Money::of_major(USD, 1) + &Money::of_major(JPY, 1); // panics!Run

The resulting type after applying the + operator

The method for the + operator

impl Sub for Money
[src]

let one = Money::of_major(USD, 1);
assert_eq!(Money::of_major(USD, 0), one.clone() - one);Run

Attempting to subtract moneys of different currencies will panic.

Money::of_major(USD, 1) - Money::of_major(JPY, 1); // panics!Run

The resulting type after applying the - operator

The method for the - operator

impl<'b> Sub<&'b Money> for Money
[src]

let one = Money::of_major(USD, 1);
assert_eq!(Money::of_major(USD, 0), one.clone() - &one);Run

Attempting to subtract moneys of different currencies will panic.

Money::of_major(USD, 1) - &Money::of_major(JPY, 1); // panics!Run

The resulting type after applying the - operator

The method for the - operator

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

let one = Money::of_major(USD, 1);
assert_eq!(Money::of_major(USD, 0), &one - one.clone());Run

Attempting to subtract moneys of different currencies will panic.

&Money::of_major(USD, 1) - Money::of_major(JPY, 1); // panics!Run

The resulting type after applying the - operator

The method for the - operator

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

let one = Money::of_major(USD, 1);
assert_eq!(Money::of_major(USD, 0), &one - &one);Run

Attempting to subtract moneys of different currencies will panic.

&Money::of_major(USD, 1) - &Money::of_major(JPY, 1); // panics!Run

The resulting type after applying the - operator

The method for the - operator

impl Mul<i64> for Money
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'b> Mul<&'b i64> for Money
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<i64> for &'a Money
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'b i64> for &'a Money
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<f64> for Money
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'b> Mul<&'b f64> for Money
[src]

The resulting type after applying the * operator

The method for the * operator

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

The resulting type after applying the * operator

The method for the * operator

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

The resulting type after applying the * operator

The method for the * operator

impl Div<i64> for Money
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'b> Div<&'b i64> for Money
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<i64> for &'a Money
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'b i64> for &'a Money
[src]

The resulting type after applying the / operator

The method for the / operator

impl Rem<i64> for Money
[src]

The resulting type after applying the % operator

The method for the % operator

impl<'b> Rem<&'b i64> for Money
[src]

The resulting type after applying the % operator

The method for the % operator

impl<'a> Rem<i64> for &'a Money
[src]

The resulting type after applying the % operator

The method for the % operator

impl<'a, 'b> Rem<&'b i64> for &'a Money
[src]

The resulting type after applying the % operator

The method for the % operator

impl Neg for Money
[src]

The resulting type after applying the - operator

The method for the unary - operator

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

The resulting type after applying the - operator

The method for the unary - operator

impl PartialOrd for Money
[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