Crates.io | jurisdiction |
lib.rs | jurisdiction |
version | 0.1.1 |
source | src |
created_at | 2020-04-06 08:40:42.979954 |
updated_at | 2020-04-27 07:49:19.929705 |
description | A lightweight API-friendly abstraction for the jurisdiction in the world, and their accompanying static information pertaining to that jurisdiction. Information available includes: * ISO 3166 country codes * UN M49 Region classifications |
homepage | https://www.orcalabs.no |
repository | https://gitlab.com/orcalabs.public/jursidiction-rs |
max_upload_size | |
id | 226820 |
size | 99,695 |
Lightweight static Jurisdiction
information.
This crate provides interfaces to work with jurisdictions for areas around the world. Information about a jurisdiction includes
The Jurisdiction object is a lightweight object, the size of a pointer, suitable for transfer in API surfaces throughout an ecosystem. Serialization on API boundaries may choose to employ any of the standardized classification formats.
use anyhow::{Result, anyhow, format_err};
use jurisdiction::{Jurisdiction, Alpha2, Alpha3};
use jurisdiction::region::{Region, SubRegion};
use std::str::FromStr;
fn supported_jurisdiction(alpha: &str) -> Result<Jurisdiction> {
let jurisdiction = Jurisdiction::from_str(alpha)?;
match jurisdiction.alpha2() {
Alpha2::NO | Alpha2::SE | Alpha2::DK => Ok(jurisdiction),
_ => Err(format_err!("only scandinavian countries are supported")),
}
}
fn main() {
let jurisdiction = supported_jurisdiction("NO").expect("unsupported");
assert_eq!(jurisdiction, Alpha2::NO);
assert_eq!(jurisdiction.alpha2(), Alpha2::NO);
assert_eq!(jurisdiction.alpha2().to_string(), "NO");
assert_eq!(jurisdiction, Alpha3::NOR);
assert_eq!(jurisdiction.alpha3(), Alpha3::NOR);
assert_eq!(jurisdiction.alpha3().to_string(), "NOR");
assert_eq!(jurisdiction.country_code(), 578);
assert_eq!(jurisdiction.region(), Region::Europe);
assert_eq!(jurisdiction.sub_region(), SubRegion::NorthernEurope);
}
See docs.rs for more extensive API documentation and examples.