[−][src]Struct steel_cent::currency::Currency
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]
pub 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.
pub 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());
pub fn numeric_code(&self) -> u16
[src]
assert_eq!(840, USD.numeric_code()); assert_eq!(392, JPY.numeric_code());
pub fn decimal_places(&self) -> u8
[src]
assert_eq!(2, USD.decimal_places()); assert_eq!(0, JPY.decimal_places());
pub 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))
pub 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))
pub 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));
pub 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));
pub 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));
pub 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 Clone for Currency
[src]
fn clone(&self) -> Currency
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for Currency
[src]
impl Eq for Currency
[src]
impl PartialEq<Currency> for Currency
[src]
impl Debug for Currency
[src]
impl Hash for Currency
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,