Expand description
Rust implementation of Countries as specified by Country Codes and ISO-3166-1
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 country
value
- The code as an integer
alpha2
- The alpha2 letter set for the country
alpha3
- The alpha3 letter set for the country
long_name
- The official state name for the country
aliases
- 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
§Usage
use celes::Country;
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
- createCountry
from three digit codefrom_alpha2
- createCountry
from two letter codefrom_alpha3
- createCountry
from three letter codefrom_alias
- createCountry
from a common alias stripped of any spaces or underscores. This only works for some countries as not all countries have aliasesfrom_name
- createCountry
from the full state name no space or underscores
Country
implements the core::str::FromStr trait that accepts any valid argument to the previously mentioned functions
such as:
- The country aliases like UnitedKingdom, GreatBritain, Russia, America
- The full country name
- The alpha2 code
- The alpha3 code
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
§From String Example
use celes::Country;
use core::str::FromStr;
// All of these are equivalent
assert_eq!("US", Country::from_str("USA").unwrap().alpha2);
assert_eq!("US", Country::from_str("US").unwrap().alpha2);
assert_eq!("US", Country::from_str("America").unwrap().alpha2);
assert_eq!("US", Country::from_str("UnitedStates").unwrap().alpha2);
assert_eq!("US", Country::from_str("TheUnitedStatesOfAmerica").unwrap().alpha2);
// All of these are equivalent
assert_eq!("GB", Country::from_str("England").unwrap().alpha2);
assert_eq!("GB", Country::from_str("gb").unwrap().alpha2);
assert_eq!("GB", Country::from_str("Scotland").unwrap().alpha2);
assert_eq!("GB", Country::from_str("TheUnitedKingdomOfGreatBritainAndNorthernIreland").unwrap().alpha2);
Structs§
- America
Table - Aliases for “The United States Of America”
- Bahamas
Table - Aliases for “The Bahamas”
- Bosnia
Table - Aliases for “Bosnia And Herzegovina”
- Brunei
Table - Aliases for “Brunei Darussalam”
- Burkina
Table - Aliases for “Burkina Faso”
- Cayman
Islands Table - Aliases for “The Cayman Islands”
- Central
African Republic Table - Aliases for “The Central African Republic”
- Cocos
Islands Table - Aliases for “The Cocos Keeling Islands”
- Comoros
Table - Aliases for “The Comoros”
- Congo
Table - Aliases for “The Congo”
- Cook
Islands Table - Aliases for “The Cook Islands”
- Country
- Represents a country according to ISO 3166
- Czechia
Table - Aliases for “Czechia”
- Democratic
Republic OfThe Congo Table - Aliases for “The Democratic Republic Of The Congo”
- Dominican
Republic Table - Aliases for “The Dominican Republic”
- Empty
Lookup Table - A lookup table with zero entries
- England
Table - Aliases for “The United Kingdom Of Great Britain And Northern Ireland”
- Faroe
Islands Table - Aliases for “The Faroe Islands”
- French
Southern Territories Table - Aliases for “The French Southern Territories”
- Gambia
Table - Aliases for “The Gambia”
- Heard
Island Table - Aliases for “Heard Island And Mc Donald Islands”
- Holy
SeeTable - Aliases for “The Holy See”
- Iran
Table - Aliases for “Islamic Republic Of Iran”
- LaoPeoples
Democratic Republic Table - Aliases for “The Lao Peoples Democratic Republic”
- Macedonia
Table - Aliases for “Republic Of North Macedonia”
- Malvinas
Table - Aliases for “The Falkland Islands Malvinas”
- Marshall
Islands Table - Aliases for “The Marshall Islands”
- Micronesia
Table - Aliases for “Federated States Of Micronesia”
- Moldova
Table - Aliases for “The Republic Of Moldova”
- Netherlands
Table - Aliases for “The Netherlands”
- Niger
Table - Aliases for “The Niger”
- North
Korea Table - Aliases for “The Democratic Peoples Republic Of Korea”
- Northern
Mariana Islands Table - Aliases for “The Northern Mariana Islands”
- Palestine
Table - Aliases for “State Of Palestine”
- Philippines
Table - Aliases for “The Philippines”
- Russia
Table - Aliases for “The Russian Federation”
- Saint
Helena Table - Aliases for “Ascension And Tristan Da Cunha Saint Helena”
- Samoa
Table - Aliases for “American Samoa”
- SaoTome
Table - Aliases for “Sao Tome And Principe”
- South
Georgia Table - Aliases for “South Georgia And The South Sandwich Islands”
- South
Korea Table - Aliases for “The Republic Of Korea”
- StBarthelemy
Table - Aliases for “Saint Barthelemy”
- StKitts
Table - Aliases for “Saint Kitts And Nevis”
- StLucia
Table - Aliases for “Saint Lucia”
- StMaarten
Table - Aliases for “Dutch Part Sint Maarten”
- StMartin
Table - Aliases for “French Part Saint Martin”
- StPierre
Table - Aliases for “Saint Pierre And Miquelon”
- StVincent
Table - Aliases for “Saint Vincent And The Grenadines”
- Sudan
Table - Aliases for “The Sudan”
- Taiwan
Table - Aliases for “Taiwan Province Of China”
- Tanzania
Table - Aliases for “United Republic Of Tanzania”
- Timor
Table - Aliases for “Timor-Leste”
- Trinidad
Table - Aliases for “Trinidad And Tobago”
- Turkey
Table - Aliases for “Türkiye”
- Turks
AndCaicos Islands Table - Aliases for “The Turks And Caicos Islands”
- United
Arab Emirates Table - Aliases for “The United Arab Emirates”
- United
States Minor Outlying Islands Table - Aliases for “The United States Minor Outlying Islands”
- Venezuela
Table - Aliases for “Bolivarian Republic Of Venezuela”
Enums§
- Country
Table - Wrapper struct for alias tables to avoid using Box
Constants§
- EMPTY_
LOOKUP_ TABLE - Since reference for the EmptyLookupTable
Traits§
- Lookup
Table - A lookup table where all elements are statically known