[][src]Struct commodity::Currency

pub struct Currency {
    pub code: CurrencyCode,
    pub name: Option<String>,
}

Represents a the type of currency held in a Commodity. See CurrencyCode for the primative which is genarally stored and used to refer to a given Currency.

Fields

code: CurrencyCode

Stores the code/id of this currency in a fixed length ArrayString, with a maximum length of CURRENCY_CODE_LENGTH.

name: Option<String>

The human readable name of this currency.

Methods

impl Currency[src]

pub fn new(code: CurrencyCode, name: Option<String>) -> Currency[src]

Create a new Currency

Example

use std::str::FromStr;

let code = CurrencyCode::from_str("AUD").unwrap();
let currency = Currency::new(
    code,
    Some(String::from("Australian Dollar"))
);

assert_eq!(code, currency.code);
assert_eq!(Some(String::from("Australian Dollar")), currency.name);

pub fn from_str(code: &str, name: &str) -> Result<Currency, CommodityError>[src]

Create a Currency from strings, usually for debugging, or unit testing purposes.

code is an array backed string that has a fixed maximum size of CURRENCY_CODE_LENGTH. The supplied string must not exeed this, or a CommodityError::TooLongCurrencyCode will be returned.

Example

use std::str::FromStr;

let currency = Currency::from_str("AUD", "Australian dollar").unwrap();

assert_eq!(CurrencyCode::from_str("AUD").unwrap(), currency.code);
assert_eq!("Australian dollar", currency.name.unwrap());

pub fn from_alpha3(alpha3: &str) -> Result<Currency, CommodityError>[src]

Construct a Currency by looking it up in the iso4217 currency database.

Example


let currency = Currency::from_alpha3("AUD").unwrap();
assert_eq!("AUD", currency.code);
assert_eq!(Some(String::from("Australian dollar")), currency.name);

Trait Implementations

impl Clone for Currency[src]

impl Debug for Currency[src]

impl<'de> Deserialize<'de> for Currency[src]

impl<'_> From<&'_ Currency> for CurrencyCode[src]

impl Serialize for Currency[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.