Crate celes

Source
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 - create Country from three digit code
  • from_alpha2 - create Country from two letter code
  • from_alpha3 - create Country from three letter code
  • from_alias - create Country from a common alias stripped of any spaces or underscores. This only works for some countries as not all countries have aliases
  • from_name - create Country 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§

AmericaTable
Aliases for “The United States Of America”
BahamasTable
Aliases for “The Bahamas”
BosniaTable
Aliases for “Bosnia And Herzegovina”
BruneiTable
Aliases for “Brunei Darussalam”
BurkinaTable
Aliases for “Burkina Faso”
CaymanIslandsTable
Aliases for “The Cayman Islands”
CentralAfricanRepublicTable
Aliases for “The Central African Republic”
CocosIslandsTable
Aliases for “The Cocos Keeling Islands”
ComorosTable
Aliases for “The Comoros”
CongoTable
Aliases for “The Congo”
CookIslandsTable
Aliases for “The Cook Islands”
Country
Represents a country according to ISO 3166
CzechiaTable
Aliases for “Czechia”
DemocraticRepublicOfTheCongoTable
Aliases for “The Democratic Republic Of The Congo”
DominicanRepublicTable
Aliases for “The Dominican Republic”
EmptyLookupTable
A lookup table with zero entries
EnglandTable
Aliases for “The United Kingdom Of Great Britain And Northern Ireland”
FaroeIslandsTable
Aliases for “The Faroe Islands”
FrenchSouthernTerritoriesTable
Aliases for “The French Southern Territories”
GambiaTable
Aliases for “The Gambia”
HeardIslandTable
Aliases for “Heard Island And Mc Donald Islands”
HolySeeTable
Aliases for “The Holy See”
IranTable
Aliases for “Islamic Republic Of Iran”
LaoPeoplesDemocraticRepublicTable
Aliases for “The Lao Peoples Democratic Republic”
MacedoniaTable
Aliases for “Republic Of North Macedonia”
MalvinasTable
Aliases for “The Falkland Islands Malvinas”
MarshallIslandsTable
Aliases for “The Marshall Islands”
MicronesiaTable
Aliases for “Federated States Of Micronesia”
MoldovaTable
Aliases for “The Republic Of Moldova”
NetherlandsTable
Aliases for “The Netherlands”
NigerTable
Aliases for “The Niger”
NorthKoreaTable
Aliases for “The Democratic Peoples Republic Of Korea”
NorthernMarianaIslandsTable
Aliases for “The Northern Mariana Islands”
PalestineTable
Aliases for “State Of Palestine”
PhilippinesTable
Aliases for “The Philippines”
RussiaTable
Aliases for “The Russian Federation”
SaintHelenaTable
Aliases for “Ascension And Tristan Da Cunha Saint Helena”
SamoaTable
Aliases for “American Samoa”
SaoTomeTable
Aliases for “Sao Tome And Principe”
SouthGeorgiaTable
Aliases for “South Georgia And The South Sandwich Islands”
SouthKoreaTable
Aliases for “The Republic Of Korea”
StBarthelemyTable
Aliases for “Saint Barthelemy”
StKittsTable
Aliases for “Saint Kitts And Nevis”
StLuciaTable
Aliases for “Saint Lucia”
StMaartenTable
Aliases for “Dutch Part Sint Maarten”
StMartinTable
Aliases for “French Part Saint Martin”
StPierreTable
Aliases for “Saint Pierre And Miquelon”
StVincentTable
Aliases for “Saint Vincent And The Grenadines”
SudanTable
Aliases for “The Sudan”
TaiwanTable
Aliases for “Taiwan Province Of China”
TanzaniaTable
Aliases for “United Republic Of Tanzania”
TimorTable
Aliases for “Timor-Leste”
TrinidadTable
Aliases for “Trinidad And Tobago”
TurkeyTable
Aliases for “Türkiye”
TurksAndCaicosIslandsTable
Aliases for “The Turks And Caicos Islands”
UnitedArabEmiratesTable
Aliases for “The United Arab Emirates”
UnitedStatesMinorOutlyingIslandsTable
Aliases for “The United States Minor Outlying Islands”
VenezuelaTable
Aliases for “Bolivarian Republic Of Venezuela”

Enums§

CountryTable
Wrapper struct for alias tables to avoid using Box

Constants§

EMPTY_LOOKUP_TABLE
Since reference for the EmptyLookupTable

Traits§

LookupTable
A lookup table where all elements are statically known