pub struct Country {
pub code: &'static str,
pub value: usize,
pub alpha2: &'static str,
pub alpha3: &'static str,
pub long_name: &'static str,
pub aliases: CountryTable,
}
Expand description
Represents a country according to ISO 3166
Fields
code: &'static str
The three digit code assigned to the country
value: usize
The integer value for code
alpha2: &'static str
The two letter country code (alpha-2) assigned to the country
alpha3: &'static str
The three letter country code (alpha-3) assigned to the country
long_name: &'static str
The official state name of the country
aliases: CountryTable
Common aliases associated with the country
Implementations
sourceimpl Country
impl Country
sourcepub fn afghanistan() -> Self
pub fn afghanistan() -> Self
Creates a struct for Afghanistan
sourcepub fn aland_islands() -> Self
pub fn aland_islands() -> Self
Creates a struct for Aland Islands
sourcepub fn american_samoa() -> Self
pub fn american_samoa() -> Self
Creates a struct for American Samoa
sourcepub fn antarctica() -> Self
pub fn antarctica() -> Self
Creates a struct for Antarctica
sourcepub fn antigua_and_barbuda() -> Self
pub fn antigua_and_barbuda() -> Self
Creates a struct for Antigua And Barbuda
sourcepub fn ascension_and_tristan_da_cunha_saint_helena() -> Self
pub fn ascension_and_tristan_da_cunha_saint_helena() -> Self
Creates a struct for Ascension And Tristan Da Cunha Saint Helena
sourcepub fn azerbaijan() -> Self
pub fn azerbaijan() -> Self
Creates a struct for Azerbaijan
sourcepub fn bangladesh() -> Self
pub fn bangladesh() -> Self
Creates a struct for Bangladesh
sourcepub fn bolivarian_republic_of_venezuela() -> Self
pub fn bolivarian_republic_of_venezuela() -> Self
Creates a struct for Bolivarian Republic Of Venezuela
sourcepub fn bosnia_and_herzegovina() -> Self
pub fn bosnia_and_herzegovina() -> Self
Creates a struct for Bosnia And Herzegovina
sourcepub fn bouvet_island() -> Self
pub fn bouvet_island() -> Self
Creates a struct for Bouvet Island
sourcepub fn british_indian_ocean_territory() -> Self
pub fn british_indian_ocean_territory() -> Self
Creates a struct for British Indian Ocean Territory
sourcepub fn british_virgin_islands() -> Self
pub fn british_virgin_islands() -> Self
Creates a struct for British Virgin Islands
sourcepub fn brunei_darussalam() -> Self
pub fn brunei_darussalam() -> Self
Creates a struct for Brunei Darussalam
sourcepub fn burkina_faso() -> Self
pub fn burkina_faso() -> Self
Creates a struct for Burkina Faso
sourcepub fn cabo_verde() -> Self
pub fn cabo_verde() -> Self
Creates a struct for Cabo Verde
sourcepub fn christmas_island() -> Self
pub fn christmas_island() -> Self
Creates a struct for Christmas Island
sourcepub fn costa_rica() -> Self
pub fn costa_rica() -> Self
Creates a struct for Costa Rica
sourcepub fn coted_ivoire() -> Self
pub fn coted_ivoire() -> Self
Creates a struct for Coted Ivoire
sourcepub fn dutch_part_sint_maarten() -> Self
pub fn dutch_part_sint_maarten() -> Self
Creates a struct for Dutch Part Sint Maarten
sourcepub fn el_salvador() -> Self
pub fn el_salvador() -> Self
Creates a struct for El Salvador
sourcepub fn equatorial_guinea() -> Self
pub fn equatorial_guinea() -> Self
Creates a struct for Equatorial Guinea
sourcepub fn federated_states_of_micronesia() -> Self
pub fn federated_states_of_micronesia() -> Self
Creates a struct for Federated States Of Micronesia
sourcepub fn french_guiana() -> Self
pub fn french_guiana() -> Self
Creates a struct for French Guiana
sourcepub fn french_part_saint_martin() -> Self
pub fn french_part_saint_martin() -> Self
Creates a struct for French Part Saint Martin
sourcepub fn french_polynesia() -> Self
pub fn french_polynesia() -> Self
Creates a struct for French Polynesia
sourcepub fn guadeloupe() -> Self
pub fn guadeloupe() -> Self
Creates a struct for Guadeloupe
sourcepub fn guinea_bissau() -> Self
pub fn guinea_bissau() -> Self
Creates a struct for Guinea Bissau
sourcepub fn heard_island_and_mc_donald_islands() -> Self
pub fn heard_island_and_mc_donald_islands() -> Self
Creates a struct for Heard Island And Mc Donald Islands
sourcepub fn islamic_republic_of_iran() -> Self
pub fn islamic_republic_of_iran() -> Self
Creates a struct for Islamic Republic Of Iran
sourcepub fn isle_of_man() -> Self
pub fn isle_of_man() -> Self
Creates a struct for Isle Of Man
sourcepub fn kazakhstan() -> Self
pub fn kazakhstan() -> Self
Creates a struct for Kazakhstan
sourcepub fn kyrgyzstan() -> Self
pub fn kyrgyzstan() -> Self
Creates a struct for Kyrgyzstan
sourcepub fn liechtenstein() -> Self
pub fn liechtenstein() -> Self
Creates a struct for Liechtenstein
sourcepub fn luxembourg() -> Self
pub fn luxembourg() -> Self
Creates a struct for Luxembourg
sourcepub fn madagascar() -> Self
pub fn madagascar() -> Self
Creates a struct for Madagascar
sourcepub fn martinique() -> Self
pub fn martinique() -> Self
Creates a struct for Martinique
sourcepub fn mauritania() -> Self
pub fn mauritania() -> Self
Creates a struct for Mauritania
sourcepub fn montenegro() -> Self
pub fn montenegro() -> Self
Creates a struct for Montenegro
sourcepub fn montserrat() -> Self
pub fn montserrat() -> Self
Creates a struct for Montserrat
sourcepub fn mozambique() -> Self
pub fn mozambique() -> Self
Creates a struct for Mozambique
sourcepub fn new_caledonia() -> Self
pub fn new_caledonia() -> Self
Creates a struct for New Caledonia
sourcepub fn new_zealand() -> Self
pub fn new_zealand() -> Self
Creates a struct for New Zealand
sourcepub fn norfolk_island() -> Self
pub fn norfolk_island() -> Self
Creates a struct for Norfolk Island
sourcepub fn papua_new_guinea() -> Self
pub fn papua_new_guinea() -> Self
Creates a struct for Papua New Guinea
sourcepub fn puerto_rico() -> Self
pub fn puerto_rico() -> Self
Creates a struct for Puerto Rico
sourcepub fn republic_of_north_macedonia() -> Self
pub fn republic_of_north_macedonia() -> Self
Creates a struct for Republic Of North Macedonia
sourcepub fn saint_barthelemy() -> Self
pub fn saint_barthelemy() -> Self
Creates a struct for Saint Barthelemy
sourcepub fn saint_kitts_and_nevis() -> Self
pub fn saint_kitts_and_nevis() -> Self
Creates a struct for Saint Kitts And Nevis
sourcepub fn saint_lucia() -> Self
pub fn saint_lucia() -> Self
Creates a struct for Saint Lucia
sourcepub fn saint_pierre_and_miquelon() -> Self
pub fn saint_pierre_and_miquelon() -> Self
Creates a struct for Saint Pierre And Miquelon
sourcepub fn saint_vincent_and_the_grenadines() -> Self
pub fn saint_vincent_and_the_grenadines() -> Self
Creates a struct for Saint Vincent And The Grenadines
sourcepub fn san_marino() -> Self
pub fn san_marino() -> Self
Creates a struct for San Marino
sourcepub fn sao_tome_and_principe() -> Self
pub fn sao_tome_and_principe() -> Self
Creates a struct for Sao Tome And Principe
sourcepub fn saudi_arabia() -> Self
pub fn saudi_arabia() -> Self
Creates a struct for Saudi Arabia
sourcepub fn seychelles() -> Self
pub fn seychelles() -> Self
Creates a struct for Seychelles
sourcepub fn sierra_leone() -> Self
pub fn sierra_leone() -> Self
Creates a struct for Sierra Leone
sourcepub fn solomon_islands() -> Self
pub fn solomon_islands() -> Self
Creates a struct for Solomon Islands
sourcepub fn south_africa() -> Self
pub fn south_africa() -> Self
Creates a struct for South Africa
sourcepub fn south_georgia_and_the_south_sandwich_islands() -> Self
pub fn south_georgia_and_the_south_sandwich_islands() -> Self
Creates a struct for South Georgia And The South Sandwich Islands
sourcepub fn south_sudan() -> Self
pub fn south_sudan() -> Self
Creates a struct for South Sudan
sourcepub fn state_of_palestine() -> Self
pub fn state_of_palestine() -> Self
Creates a struct for State Of Palestine
sourcepub fn svalbard_and_jan_mayen() -> Self
pub fn svalbard_and_jan_mayen() -> Self
Creates a struct for Svalbard And Jan Mayen
sourcepub fn switzerland() -> Self
pub fn switzerland() -> Self
Creates a struct for Switzerland
sourcepub fn syrian_arab_republic() -> Self
pub fn syrian_arab_republic() -> Self
Creates a struct for Syrian Arab Republic
sourcepub fn taiwan_province_of_china() -> Self
pub fn taiwan_province_of_china() -> Self
Creates a struct for Taiwan Province Of China
sourcepub fn tajikistan() -> Self
pub fn tajikistan() -> Self
Creates a struct for Tajikistan
sourcepub fn the_bahamas() -> Self
pub fn the_bahamas() -> Self
Creates a struct for The Bahamas
sourcepub fn the_cayman_islands() -> Self
pub fn the_cayman_islands() -> Self
Creates a struct for The Cayman Islands
sourcepub fn the_central_african_republic() -> Self
pub fn the_central_african_republic() -> Self
Creates a struct for The Central African Republic
sourcepub fn the_cocos_keeling_islands() -> Self
pub fn the_cocos_keeling_islands() -> Self
Creates a struct for The Cocos Keeling Islands
sourcepub fn the_comoros() -> Self
pub fn the_comoros() -> Self
Creates a struct for The Comoros
sourcepub fn the_cook_islands() -> Self
pub fn the_cook_islands() -> Self
Creates a struct for The Cook Islands
sourcepub fn the_democratic_peoples_republic_of_korea() -> Self
pub fn the_democratic_peoples_republic_of_korea() -> Self
Creates a struct for The Democratic Peoples Republic Of Korea
sourcepub fn the_democratic_republic_of_the_congo() -> Self
pub fn the_democratic_republic_of_the_congo() -> Self
Creates a struct for The Democratic Republic Of The Congo
sourcepub fn the_dominican_republic() -> Self
pub fn the_dominican_republic() -> Self
Creates a struct for The Dominican Republic
sourcepub fn the_falkland_islands_malvinas() -> Self
pub fn the_falkland_islands_malvinas() -> Self
Creates a struct for The Falkland Islands Malvinas
sourcepub fn the_faroe_islands() -> Self
pub fn the_faroe_islands() -> Self
Creates a struct for The Faroe Islands
sourcepub fn the_french_southern_territories() -> Self
pub fn the_french_southern_territories() -> Self
Creates a struct for The French Southern Territories
sourcepub fn the_gambia() -> Self
pub fn the_gambia() -> Self
Creates a struct for The Gambia
sourcepub fn the_holy_see() -> Self
pub fn the_holy_see() -> Self
Creates a struct for The Holy See
sourcepub fn the_lao_peoples_democratic_republic() -> Self
pub fn the_lao_peoples_democratic_republic() -> Self
Creates a struct for The Lao Peoples Democratic Republic
sourcepub fn the_marshall_islands() -> Self
pub fn the_marshall_islands() -> Self
Creates a struct for The Marshall Islands
sourcepub fn the_netherlands() -> Self
pub fn the_netherlands() -> Self
Creates a struct for The Netherlands
sourcepub fn the_northern_mariana_islands() -> Self
pub fn the_northern_mariana_islands() -> Self
Creates a struct for The Northern Mariana Islands
sourcepub fn the_philippines() -> Self
pub fn the_philippines() -> Self
Creates a struct for The Philippines
sourcepub fn the_republic_of_korea() -> Self
pub fn the_republic_of_korea() -> Self
Creates a struct for The Republic Of Korea
sourcepub fn the_republic_of_moldova() -> Self
pub fn the_republic_of_moldova() -> Self
Creates a struct for The Republic Of Moldova
sourcepub fn the_russian_federation() -> Self
pub fn the_russian_federation() -> Self
Creates a struct for The Russian Federation
sourcepub fn the_turks_and_caicos_islands() -> Self
pub fn the_turks_and_caicos_islands() -> Self
Creates a struct for The Turks And Caicos Islands
sourcepub fn the_united_arab_emirates() -> Self
pub fn the_united_arab_emirates() -> Self
Creates a struct for The United Arab Emirates
sourcepub fn the_united_kingdom_of_great_britain_and_northern_ireland() -> Self
pub fn the_united_kingdom_of_great_britain_and_northern_ireland() -> Self
Creates a struct for The United Kingdom Of Great Britain And Northern Ireland
sourcepub fn the_united_states_minor_outlying_islands() -> Self
pub fn the_united_states_minor_outlying_islands() -> Self
Creates a struct for The United States Minor Outlying Islands
sourcepub fn the_united_states_of_america() -> Self
pub fn the_united_states_of_america() -> Self
Creates a struct for The United States Of America
sourcepub fn timor_leste() -> Self
pub fn timor_leste() -> Self
Creates a struct for Timor Leste
sourcepub fn trinidad_and_tobago() -> Self
pub fn trinidad_and_tobago() -> Self
Creates a struct for Trinidad And Tobago
sourcepub fn turkmenistan() -> Self
pub fn turkmenistan() -> Self
Creates a struct for Turkmenistan
sourcepub fn us_virgin_islands() -> Self
pub fn us_virgin_islands() -> Self
Creates a struct for US Virgin Islands
sourcepub fn united_republic_of_tanzania() -> Self
pub fn united_republic_of_tanzania() -> Self
Creates a struct for United Republic Of Tanzania
sourcepub fn uzbekistan() -> Self
pub fn uzbekistan() -> Self
Creates a struct for Uzbekistan
sourcepub fn wallis_and_futuna() -> Self
pub fn wallis_and_futuna() -> Self
Creates a struct for Wallis And Futuna
sourcepub fn western_sahara() -> Self
pub fn western_sahara() -> Self
Creates a struct for Western Sahara
sourcepub fn get_countries() -> [Self; 250]
pub fn get_countries() -> [Self; 250]
Returns a vector in alphabetic order of all the countries
use celes::Country;
use std::collections::BTreeMap;
let countries = Country::get_countries();
for c in &countries {
println!("{}", c);
}
for c in &countries {
println!("{}", c.alpha2);
}
for c in countries.iter().filter(|cty| cty.value < 300) {
println!("{}", c.long_name)
}
//Convert to a map
let lookup = countries.iter().map(|cty| (cty.alpha2.to_string(), cty.clone())).collect::<BTreeMap<String, Country>>();
sourcepub fn from_value(value: usize) -> Result<Self, &'static str>
pub fn from_value(value: usize) -> Result<Self, &'static str>
Given the numeric code, return a country or an error if the parameter doesn’t match any country
use celes::Country;
let res = Country::from_value(1);
assert!(res.is_err());
let res = Country::from_value(2);
assert!(res.is_err());
let res = Country::from_value(4);
assert!(res.is_ok());
assert_eq!(Country::afghanistan(), res.unwrap());
sourcepub fn from_code<A: AsRef<str>>(code: A) -> Result<Self, &'static str>
pub fn from_code<A: AsRef<str>>(code: A) -> Result<Self, &'static str>
Given the three digit code, return a country or an error if the parameter doesn’t match any country. The value MUST be the three digit code which includes leading zeros.
use celes::Country;
let res = Country::from_code("8");
assert!(res.is_err());
let res = Country::from_code("08");
assert!(res.is_err());
let res = Country::from_code("008");
assert!(res.is_ok());
assert_eq!(Country::albania(), res.unwrap());
sourcepub fn from_alpha2<A: AsRef<str>>(alpha2: A) -> Result<Self, &'static str>
pub fn from_alpha2<A: AsRef<str>>(alpha2: A) -> Result<Self, &'static str>
Given the alpha2 letters, return a country or an error if the parameter doesn’t match any country. This is case-insensitive.
use celes::Country;
let res = Country::from_alpha2("u");
assert!(res.is_err());
let res = Country::from_alpha2("us");
assert!(res.is_ok());
assert_eq!(Country::the_united_states_of_america(), res.unwrap());
let res = Country::from_alpha2("Us");
assert_eq!(Country::the_united_states_of_america(), res.unwrap());
let res = Country::from_alpha2("uS");
assert_eq!(Country::the_united_states_of_america(), res.unwrap());
let res = Country::from_alpha2("US");
assert_eq!(Country::the_united_states_of_america(), res.unwrap());
sourcepub fn from_alpha3<A: AsRef<str>>(alpha3: A) -> Result<Self, &'static str>
pub fn from_alpha3<A: AsRef<str>>(alpha3: A) -> Result<Self, &'static str>
Given the alpha3 letters, return a country or an error if the parameter doesn’t match any country. This is case-insensitive.
use celes::Country;
let res = Country::from_alpha3("u");
assert!(res.is_err());
let res = Country::from_alpha3("us");
assert!(res.is_err());
let res = Country::from_alpha3("Usa");
assert_eq!(Country::the_united_states_of_america(), res.unwrap());
let res = Country::from_alpha3("uSa");
assert_eq!(Country::the_united_states_of_america(), res.unwrap());
let res = Country::from_alpha3("USA");
assert_eq!(Country::the_united_states_of_america(), res.unwrap());
sourcepub fn from_alias<A: AsRef<str>>(alias: A) -> Result<Self, &'static str>
pub fn from_alias<A: AsRef<str>>(alias: A) -> Result<Self, &'static str>
Given the a country alias, return a country or an error if the parameter doesn’t match any country
The alias is any value in the aliases
field for a country.
For example, “america” would return the_united_states_of_america
This is case-insensitive.
use celes::Country;
let res = Country::from_alias("u");
assert!(res.is_err());
let res = Country::from_alias("us");
assert!(res.is_err());
let res = Country::from_alias("america");
assert_eq!(Country::the_united_states_of_america(), res.unwrap());
let res = Country::from_alias("russia");
assert_eq!(Country::the_russian_federation(), res.unwrap());
let res = Country::from_alias("england");
assert_eq!(Country::the_united_kingdom_of_great_britain_and_northern_ireland(), res.unwrap());
sourcepub fn from_name<A: AsRef<str>>(name: A) -> Result<Self, &'static str>
pub fn from_name<A: AsRef<str>>(name: A) -> Result<Self, &'static str>
Given the country name, return a country or an error if the parameter doesn’t match any country. This is case-insensitive.
For example, Albania, Algeria, Brazil would return the country struct that represents those countries.
use celes::Country;
let res = Country::from_name("russianfederation");
assert!(res.is_err());
let res = Country::from_name("unitedstatesofamerica");
assert!(res.is_err());
let res = Country::from_name("Albania");
assert_eq!(Country::albania(), res.unwrap());
let res = Country::from_name("theunitedstatesofamerica");
assert_eq!(Country::the_united_states_of_america(), res.unwrap());
let res = Country::from_name("therussianfederation");
assert_eq!(Country::the_russian_federation(), res.unwrap());
let res = Country::from_name("theunitedkingdomofgreatbritainandnorthernireland");
assert_eq!(Country::the_united_kingdom_of_great_britain_and_northern_ireland(), res.unwrap());
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Country
impl<'de> Deserialize<'de> for Country
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Ord for Country
impl Ord for Country
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<Country> for Country
impl PartialEq<Country> for Country
sourceimpl PartialOrd<Country> for Country
impl PartialOrd<Country> for Country
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Country
impl Eq for Country
Auto Trait Implementations
impl RefUnwindSafe for Country
impl Send for Country
impl Sync for Country
impl Unpin for Country
impl UnwindSafe for Country
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more