Struct steel_cent::currency::Currency [] [src]

pub struct Currency { /* fields omitted */ }

A monetary currency with text and numeric codes and a standard number of decimal places, as per ISO 4217.

Three-letter currency codes are encoded in a u16, which is how this type can be small and Copy.

assert_eq!(4, std::mem::size_of::<Currency>());Run

Methods

impl Currency
[src]

Create a currency w/ the given 3-character code, 0-999 numeric code, and 0-8 decimal places. Panics if any arg violates those constraints. This function has no connection to the global currency maps used by lookup functions, so creating a custom currency won't cause it to show up in look-ups.

assert_eq!("AUD", AUD.code());
assert_eq!("CAD", CAD.code());
assert_eq!("CHF", CHF.code());
assert_eq!("EUR", EUR.code());
assert_eq!("GBP", GBP.code());
assert_eq!("JPY", JPY.code());
assert_eq!("USD", USD.code());
assert_eq!("XTS", Currency::new("XTS", 999, 2).code());Run

assert_eq!(840, USD.numeric_code());
assert_eq!(392, JPY.numeric_code());Run

assert_eq!(2, USD.decimal_places());
assert_eq!(0, JPY.decimal_places());Run

Converts a "major" amount to a "minor" amount in this currency.

assert_eq!(100, USD.major_to_minor(1));
assert_eq!(100, JPY.major_to_minor(100))Run

assert_eq!(100, USD.major_to_minor_i32(1));
assert_eq!(100, JPY.major_to_minor_i32(100))Run

Returns the major part of a minor amount.

assert_eq!(12, USD.major_part(1234));
assert_eq!(1234, JPY.major_part(1234));Run

assert_eq!(12, USD.major_part_i32(1234));
assert_eq!(1234, JPY.major_part_i32(1234));Run

Returns the minor part of a minor amount.

assert_eq!(34, USD.minor_part(1234));
assert_eq!(0, JPY.minor_part(1234));Run

assert_eq!(34, USD.minor_part_i32(1234));
assert_eq!(0, JPY.minor_part_i32(1234));Run

Trait Implementations

impl Debug for Currency
[src]

Formats the value using the given formatter.

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

impl Copy for Currency
[src]

impl Clone for Currency
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Hash for Currency
[src]

Feeds this value into the state given, updating the hasher as necessary.

Feeds a slice of this type into the state provided.