iso3166-static 0.2.0

Static ISO3166 Data
Documentation

ISO 3166 Static Data

CratesDocsDependency StatusLicense

This crate provides a generated enumeration for use as an ISO 3166-1 code enum, and some wrapper types with more strict conventions. This crate is both no-std and no-alloc (with no need/desire to enable them), and supports serde via the "serde" feature.

There are three primary objects in this crate:

  • Numeric - The ISO 3166-1 numeric country codes.
  • Alpha2 - A newtype wrapper which strictly enforces the use of Alpha2 strings.
  • Alpha3 - A newtype wrapper which strictly enforces the use of Alpha3 strings.

Examples

use iso3166_static::{Alpha2, Alpha3, Numeric};

const USA_ALPHA2: &str = "US";

let alpha2 = Alpha2::from_alpha2(USA_ALPHA2).expect("alpha2");
let alpha3 = Alpha3::from(alpha2.clone());
let numeric = Numeric::from(alpha3.clone());

assert_eq!(USA_ALPHA2, alpha2.as_str());
assert_eq!(alpha2, alpha3);
assert_eq!(alpha2, numeric);
assert_eq!(alpha3, numeric);
use core::str::FromStr;
use iso3166_static::{Alpha2, Alpha3, Numeric};

let USA_ALPHA3: &str = "USA";

let numeric = Numeric::from_str(USA_ALPHA3).expect("numeric");
let alpha3 = Alpha3::from(numeric.clone());
let alpha2 = Alpha2::from(numeric.clone());

assert_eq!(alpha3.as_str(), USA_ALPHA3);
assert_eq!(numeric, alpha3);
assert_eq!(numeric, alpha2);
assert_eq!(alpha3, alpha2);