Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust_iso4217

Crates.io Documentation License Sponsor

ISO 4217 currency, fund, precious-metal, and historic-code data for Rust and WebAssembly.

The crate provides alpha-code, numeric-code, and ISO 3166-1 alpha-3 country lookups backed by compile-time perfect hash maps.

Installation

[dependencies]
rust_iso4217 = "0.1.4"

The minimum supported Rust version is 1.85.

Usage

use rust_iso4217::{from_code, from_country, from_numeric, from_numeric_str};

assert_eq!(from_code("eur"), Some(rust_iso4217::EUR));
assert_eq!(from_numeric(360), Some(rust_iso4217::IDR));
assert_eq!(from_numeric_str("643"), Some(rust_iso4217::RUB));
assert_eq!(from_country("chn"), vec![rust_iso4217::CNY]);

// Unknown country codes return an empty vector.
assert!(from_country("unknown").is_empty());

The complete collections are available through ALL_CODES, ALL_MAP, NUMERIC_MAP, COUNTRY_MAP, ALL_ACTIVE_CODE, ALL_FUNDS_CODE, and ALL_HISTORIC_CODE.

Each entry is represented by:

pub struct CurrencyCode {
    pub name: &'static str,
    pub code: &'static str,
    pub numeric: i32,
    pub unit: i32,
    pub code_type: &'static str, // "currency", "funds", or "historic"
    pub countries: &'static [&'static str], // ISO 3166-1 alpha-3 codes
}

For entries where ISO 4217 specifies no numeric code or minor unit, the value is -1.

WebAssembly

Build the browser-targeted npm package with:

scripts/build-wasm.sh

The generated JavaScript API includes from_code, from_numeric, from_numeric_str, from_country, all_active_code, all_funds_code, and all_historic_code.

Data sources and freshness

The generated data was verified on 2026-09-28 against:

  • SIX Group, the official ISO 4217 Maintenance Agency, for List One, List Two, and List Three.
  • Datahub Country Codes, for ISO 3166-1 country-to-currency relationships.

The current SIX List One and List Three files are unchanged from the 2026-01-01 data refresh. List Two includes the Arab Accounting Dinar (XAD), which is exposed as a funds code.

To regenerate the checked-in Rust source, install the Python dependencies and run the generator from the scripts directory:

python3 -m pip install -r scripts/requirements.txt
cd scripts
python3 generate.py > ../src/lib.rs

Format and test the generated source before committing it.

Contributing

Bug reports, data corrections, and pull requests are welcome in the GitHub repository.

Sponsors

If this project saves you time, you can support its maintenance on Ko-fi.

License

Licensed under the Apache License 2.0.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages