Crates.io | celes |
lib.rs | celes |
version | |
source | src |
created_at | 2019-11-22 17:21:22.597785 |
updated_at | 2024-11-07 20:20:05.483836 |
description | Rust crate for handling ISO 3166-1. Each country has a three digit code, two letter code, three letter code, full state name, and short english aliases. |
homepage | https://crates.io/crates/celes |
repository | https://github.com/mikelodder7/celes |
max_upload_size | |
id | 183527 |
Cargo.toml error: | TOML parse error at line 25, column 1 | 25 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Convenience crate for handling ISO 3166-1. Also compatible with no-std
environments.
If there are any countries missing then please let me know or submit a PR
The main struct is Country
which provides the following properties
code
- The three digit code for the countryvalue
- The code as an integeralpha2
- The alpha2 letter set for the countryalpha3
- The alpha3 letter set for the countrylong_name
- The official state name for the countryaliases
- Other names by which the country is known. For example,The Russian Federation is also called Russia or The United Kingdom of Great Britain and Northern Ireland is also called England, Great Britain, Northern Ireland, Scotland, and United Kingdom.
Each country can be instantiated by using a function with the country name in snake case
use celes::Country;
fn main() {
let gb = Country::the_united_kingdom_of_great_britain_and_northern_ireland();
println!("{}", gb);
let usa = Country::the_united_states_of_america();
println!("{}", usa);
}
Additionally, each country can be created from a string or its numeric code.
Country
provides multiple from methods to instantiate it from a string:
from_code
- create Country
from three digit codefrom_alpha2
- create Country
from two letter codefrom_alpha3
- create Country
from three letter codefrom_alias
- create Country
from a common alias. This only works for some countries as not all countries have aliasesfrom_name
- create Country
from the full state name no space or underscoresCountry
implements the core::str::FromStr trait that accepts any valid argument to the previously mentioned functions
such as:
If you are uncertain which function to use, just use Country::from_str
as it accepts
any of the valid string values. Country::from_str
is case-insensitive
use celes::Country;
use core::str::FromStr;
fn main() {
// All three of these are equivalent
let usa_1 = Country::from_str("USA").unwrap();
let usa_2 = Country::from_str("US").unwrap();
let usa_3 = Country::from_str("America").unwrap();
// All three of these are equivalent
let gb_1 = Country::from_str("England").unwrap();
let gb_2 = Country::from_str("gb").unwrap();
let gb_3 = Country::from_str("Scotland").unwrap();
}
Licensed under
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.