iso4217-static 0.2.1

Static ISO 4217 Data
Documentation

Static ISO 4217 Data

Crates.ioDocs StatusMSRV 1.88.0

This crate provides generated ISO 4217 data. The primary point is the [Currency] enum, which contains enumrated values for the distributed currencies.

Examples

The enumeration can be created from the three-character currency code:

use iso4217_static::Currency;
use std::str::FromStr;

const CURRENCY: &str = "USD";

let actual = Currency::from_str(CURRENCY).expect("valid code");
assert_eq!(Currency::UsDollar, actual);
assert_eq!(CURRENCY, actual.as_ref());

Numeric codes are also supported:

use iso4217_static::Currency;
use std::str::FromStr;

const CURRENCY: u16 = 840;

let actual = Currency::try_from(CURRENCY).expect("valid code");
assert_eq!(Currency::UsDollar, actual);
assert_eq!(CURRENCY, actual as u16);

There are also methods to get the universal currency for a given country (if the country has one):

use iso3166_static::Alpha2;
use iso4217_static::Currency;
use std::str::FromStr;

let actual = Currency::try_from(Alpha2::UnitedStatesOfAmerica).expect("country");
assert_eq!(Currency::UsDollar, actual);