Expand description
Static ISO 3166 Data
§ISO 3166 Static Data
This crate provides generated enumerations for use as with ISO 3166-1 codes. 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- Numeric country codes.Alpha2- Two-character country codes.Alpha3- Three-character country codes.
§Features
By default, this crate compiles with serde enabled, and alloc disabled. If your compilation enables the alloc feature on the serde crate, you should enable it here as well to prevent deserialization failures.
default: Enables theserdefeature by default.alloc: Enables the use of thealloccrate.serde: Enables implementations of theserde::Deserializeandserde::Serializetraits.
§Examples
use iso3166_static::{Alpha2, Alpha3, Numeric};
const USA_ALPHA2: &str = "US";
let alpha2 = Alpha2::try_from(USA_ALPHA2).expect("alpha2");
let alpha3 = Alpha3::try_from(alpha2.clone()).expect("alpha3");
let numeric = Numeric::try_from(alpha3.clone()).expect("numeric");
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::UnitedStatesOfAmerica;
let alpha3 = Alpha3::try_from(numeric.clone()).expect("alpha3");
let alpha2 = Alpha2::try_from(numeric.clone()).expect("alpha2");
assert_eq!(alpha3.as_str(), USA_ALPHA3);
assert_eq!(numeric, alpha3);
assert_eq!(numeric, alpha2);
assert_eq!(alpha3, alpha2);