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>());
Methods
impl Currency
[src]
fn new(code: &str, numeric_code: u16, decimal_places: u8) -> Self
[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.
fn code(&self) -> String
[src]
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());
fn numeric_code(&self) -> u16
[src]
assert_eq!(840, USD.numeric_code()); assert_eq!(392, JPY.numeric_code());
fn decimal_places(&self) -> u8
[src]
assert_eq!(2, USD.decimal_places()); assert_eq!(0, JPY.decimal_places());
fn major_to_minor(&self, major: i64) -> i64
[src]
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))
fn major_to_minor_i32(&self, major: i32) -> i32
[src]
assert_eq!(100, USD.major_to_minor_i32(1)); assert_eq!(100, JPY.major_to_minor_i32(100))
fn major_part(&self, minor_amount: i64) -> i64
[src]
Returns the major part of a minor amount.
assert_eq!(12, USD.major_part(1234)); assert_eq!(1234, JPY.major_part(1234));
fn major_part_i32(&self, minor_amount: i32) -> i32
[src]
assert_eq!(12, USD.major_part_i32(1234)); assert_eq!(1234, JPY.major_part_i32(1234));
fn minor_part(&self, minor_amount: i64) -> i64
[src]
Returns the minor part of a minor amount.
assert_eq!(34, USD.minor_part(1234)); assert_eq!(0, JPY.minor_part(1234));
fn minor_part_i32(&self, minor_amount: i32) -> i32
[src]
assert_eq!(34, USD.minor_part_i32(1234)); assert_eq!(0, JPY.minor_part_i32(1234));
Trait Implementations
impl Debug for Currency
[src]
impl PartialEq for Currency
[src]
fn eq(&self, __arg_0: &Currency) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Currency) -> bool
[src]
This method tests for !=
.
impl Eq for Currency
[src]
impl Copy for Currency
[src]
impl Clone for Currency
[src]
fn clone(&self) -> Currency
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more