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

Creates a struct for Afghanistan

Creates a struct for Aland Islands

Creates a struct for Albania

Creates a struct for Algeria

Creates a struct for American Samoa

Creates a struct for Andorra

Creates a struct for Angola

Creates a struct for Anguilla

Creates a struct for Antarctica

Creates a struct for Antigua And Barbuda

Creates a struct for Argentina

Creates a struct for Armenia

Creates a struct for Aruba

Creates a struct for Ascension And Tristan Da Cunha Saint Helena

Creates a struct for Australia

Creates a struct for Austria

Creates a struct for Azerbaijan

Creates a struct for Bahrain

Creates a struct for Bangladesh

Creates a struct for Barbados

Creates a struct for Belarus

Creates a struct for Belgium

Creates a struct for Belize

Creates a struct for Benin

Creates a struct for Bermuda

Creates a struct for Bhutan

Creates a struct for Bolivarian Republic Of Venezuela

Creates a struct for Bolivia

Creates a struct for Bonaire

Creates a struct for Bosnia And Herzegovina

Creates a struct for Botswana

Creates a struct for Bouvet Island

Creates a struct for Brazil

Creates a struct for British Indian Ocean Territory

Creates a struct for British Virgin Islands

Creates a struct for Brunei Darussalam

Creates a struct for Bulgaria

Creates a struct for Burkina Faso

Creates a struct for Burundi

Creates a struct for Cabo Verde

Creates a struct for Cambodia

Creates a struct for Cameroon

Creates a struct for Canada

Creates a struct for Chad

Creates a struct for Chile

Creates a struct for China

Creates a struct for Christmas Island

Creates a struct for Colombia

Creates a struct for Costa Rica

Creates a struct for Coted Ivoire

Creates a struct for Croatia

Creates a struct for Cuba

Creates a struct for Curacao

Creates a struct for Cyprus

Creates a struct for Czechia

Creates a struct for Denmark

Creates a struct for Djibouti

Creates a struct for Dominica

Creates a struct for Dutch Part Sint Maarten

Creates a struct for Ecuador

Creates a struct for Egypt

Creates a struct for El Salvador

Creates a struct for Equatorial Guinea

Creates a struct for Eritrea

Creates a struct for Estonia

Creates a struct for Eswatini

Creates a struct for Ethiopia

Creates a struct for Federated States Of Micronesia

Creates a struct for Fiji

Creates a struct for Finland

Creates a struct for France

Creates a struct for French Guiana

Creates a struct for French Part Saint Martin

Creates a struct for French Polynesia

Creates a struct for Gabon

Creates a struct for Georgia

Creates a struct for Germany

Creates a struct for Ghana

Creates a struct for Gibraltar

Creates a struct for Greece

Creates a struct for Greenland

Creates a struct for Grenada

Creates a struct for Guadeloupe

Creates a struct for Guam

Creates a struct for Guatemala

Creates a struct for Guernsey

Creates a struct for Guinea

Creates a struct for Guinea Bissau

Creates a struct for Guyana

Creates a struct for Haiti

Creates a struct for Heard Island And Mc Donald Islands

Creates a struct for Honduras

Creates a struct for Hong Kong

Creates a struct for Hungary

Creates a struct for Iceland

Creates a struct for India

Creates a struct for Indonesia

Creates a struct for Iraq

Creates a struct for Ireland

Creates a struct for Islamic Republic Of Iran

Creates a struct for Isle Of Man

Creates a struct for Israel

Creates a struct for Italy

Creates a struct for Jamaica

Creates a struct for Japan

Creates a struct for Jersey

Creates a struct for Jordan

Creates a struct for Kazakhstan

Creates a struct for Kenya

Creates a struct for Kiribati

Creates a struct for Kosovo

Creates a struct for Kuwait

Creates a struct for Kyrgyzstan

Creates a struct for Latvia

Creates a struct for Lebanon

Creates a struct for Lesotho

Creates a struct for Liberia

Creates a struct for Libya

Creates a struct for Liechtenstein

Creates a struct for Lithuania

Creates a struct for Luxembourg

Creates a struct for Macao

Creates a struct for Madagascar

Creates a struct for Malawi

Creates a struct for Malaysia

Creates a struct for Maldives

Creates a struct for Mali

Creates a struct for Malta

Creates a struct for Martinique

Creates a struct for Mauritania

Creates a struct for Mauritius

Creates a struct for Mayotte

Creates a struct for Mexico

Creates a struct for Monaco

Creates a struct for Mongolia

Creates a struct for Montenegro

Creates a struct for Montserrat

Creates a struct for Morocco

Creates a struct for Mozambique

Creates a struct for Myanmar

Creates a struct for Namibia

Creates a struct for Nauru

Creates a struct for Nepal

Creates a struct for New Caledonia

Creates a struct for New Zealand

Creates a struct for Nicaragua

Creates a struct for Nigeria

Creates a struct for Niue

Creates a struct for Norfolk Island

Creates a struct for Norway

Creates a struct for Oman

Creates a struct for Pakistan

Creates a struct for Palau

Creates a struct for Panama

Creates a struct for Papua New Guinea

Creates a struct for Paraguay

Creates a struct for Peru

Creates a struct for Pitcairn

Creates a struct for Poland

Creates a struct for Portugal

Creates a struct for Puerto Rico

Creates a struct for Qatar

Creates a struct for Republic Of North Macedonia

Creates a struct for Reunion

Creates a struct for Romania

Creates a struct for Rwanda

Creates a struct for Saint Barthelemy

Creates a struct for Saint Kitts And Nevis

Creates a struct for Saint Lucia

Creates a struct for Saint Pierre And Miquelon

Creates a struct for Saint Vincent And The Grenadines

Creates a struct for Samoa

Creates a struct for San Marino

Creates a struct for Sao Tome And Principe

Creates a struct for Saudi Arabia

Creates a struct for Senegal

Creates a struct for Serbia

Creates a struct for Seychelles

Creates a struct for Sierra Leone

Creates a struct for Singapore

Creates a struct for Slovakia

Creates a struct for Slovenia

Creates a struct for Solomon Islands

Creates a struct for Somalia

Creates a struct for South Africa

Creates a struct for South Georgia And The South Sandwich Islands

Creates a struct for South Sudan

Creates a struct for Spain

Creates a struct for Sri Lanka

Creates a struct for State Of Palestine

Creates a struct for Suriname

Creates a struct for Svalbard And Jan Mayen

Creates a struct for Sweden

Creates a struct for Switzerland

Creates a struct for Syrian Arab Republic

Creates a struct for Taiwan Province Of China

Creates a struct for Tajikistan

Creates a struct for Thailand

Creates a struct for The Bahamas

Creates a struct for The Cayman Islands

Creates a struct for The Central African Republic

Creates a struct for The Cocos Keeling Islands

Creates a struct for The Comoros

Creates a struct for The Congo

Creates a struct for The Cook Islands

Creates a struct for The Democratic Peoples Republic Of Korea

Creates a struct for The Democratic Republic Of The Congo

Creates a struct for The Dominican Republic

Creates a struct for The Falkland Islands Malvinas

Creates a struct for The Faroe Islands

Creates a struct for The French Southern Territories

Creates a struct for The Gambia

Creates a struct for The Holy See

Creates a struct for The Lao Peoples Democratic Republic

Creates a struct for The Marshall Islands

Creates a struct for The Netherlands

Creates a struct for The Niger

Creates a struct for The Northern Mariana Islands

Creates a struct for The Philippines

Creates a struct for The Republic Of Korea

Creates a struct for The Republic Of Moldova

Creates a struct for The Russian Federation

Creates a struct for The Sudan

Creates a struct for The Turks And Caicos Islands

Creates a struct for The United Arab Emirates

Creates a struct for The United Kingdom Of Great Britain And Northern Ireland

Creates a struct for The United States Minor Outlying Islands

Creates a struct for The United States Of America

Creates a struct for Timor Leste

Creates a struct for Togo

Creates a struct for Tokelau

Creates a struct for Tonga

Creates a struct for Trinidad And Tobago

Creates a struct for Tunisia

Creates a struct for Turkey

Creates a struct for Turkmenistan

Creates a struct for Tuvalu

Creates a struct for US Virgin Islands

Creates a struct for Uganda

Creates a struct for Ukraine

Creates a struct for United Republic Of Tanzania

Creates a struct for Uruguay

Creates a struct for Uzbekistan

Creates a struct for Vanuatu

Creates a struct for Vietnam

Creates a struct for Wallis And Futuna

Creates a struct for Western Sahara

Creates a struct for Yemen

Creates a struct for Zambia

Creates a struct for Zimbabwe

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>>();

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());

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());

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());

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());

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());

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.