countries-iso3166 1.1.0

Simple Conversion for Country Codes and Names using ISO 3166
Documentation
  • Coverage
  • 0.79%
    2 out of 252 items documented1 out of 1 items with examples
  • Size
  • Source code size: 60.6 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.34 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • 448-OG/Countries-ISO3166
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • 448-OG

countries-iso3166

Rust crates.ioDocs

This crate is used to convert between UTF-8 Strings and country codes for easier handling of country names in ISO 3166 format. It has no dependencies and no_std compatible. The country names are converted to country codes in rust because country names can contain special characters not common in English which can cause confusion.

The current implementation is only for ISO 3166-1 https://en.wikipedia.org/wiki/ISO_3166-1.

Planned implementation for ISO 3166-3 https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3

Examples

use countries_iso3166::CountryIso31661;

// Initializing the `CountryIso31661` using a code
let country = CountryIso31661::KE;

// Getting the name for the country
country.as_str();

//Getting the code for the country
country.country_code();

//
// -- Convertions from a &str --
//

// Converting from a country's name
let country = "Kenya";
let country_code_iso_31661: CountryIso31661 = country.into();

let into_str: &str = country_code_iso_31661.into();
assert_eq!(into_str, country);

assert_eq!(country_code_iso_31661, CountryIso31661::KE);


// Converting from a country's code
let country_code = "KE";
let code: CountryIso31661 = country.into();
assert!(code == CountryIso31661::KE);

// Countries with special characters are also supported if the characters are UTF-8
let country = "Côte d'Ivoire";
let country_code_iso_31661: CountryIso31661 = country.into();

let into_str: &str = country_code_iso_31661.into();
assert_eq!(into_str, country);

assert_eq!(country_code_iso_31661, CountryIso31661::CI);
        

LICENSE

This code is licensed under APACHE-2.0 or MIT license.

Code of Conduct

All contributions and communication must adhere to the Rust Code of Conduct