Expand description

Rust implementation of Countries as specified by https://www.iban.com/country-codes using ISO 3166-1 and https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes

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


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


Aliases for “The United States Of America”

Aliases for “The Bahamas”

Aliases for “Bosnia And Herzegovina”

Aliases for “Brunei Darussalam”

Aliases for “Burkina Faso”

Aliases for “The Cayman Islands”

Aliases for “The Central African Republic”

Aliases for “The Cocos Keeling Islands”

Aliases for “The Comoros”

Aliases for “The Congo”

Aliases for “The Cook Islands”

Represents a country according to ISO 3166

Aliases for “The Democratic Republic Of The Congo”

Aliases for “The Dominican Republic”

A lookup table with zero entries

Aliases for “The United Kingdom Of Great Britain And Northern Ireland”

Aliases for “The Faroe Islands”

Aliases for “The French Southern Territories”

Aliases for “The Gabmia”

Aliases for “Heard Island And Mc Donald Islands”

Aliases for “The Holy See”

Aliases for “Islamic Republic Of Iran”

Aliases for “The Lao Peoples Democratic Republic”

Aliases for “Republic Of North Macedonia”

Aliases for “The Falkland Islands Malvinas”

Aliases for “The Marshall Islands”

Aliases for “Federated States Of Micronesia”

Aliases for “The Republic Of Moldova”

Aliases for “The Netherlands”

Aliases for “The Niger”

Aliases for “The Democratic Peoples Republic Of Korea”

Aliases for “The Northern Mariana Islands”

Aliases for “State Of Palestine”

Aliases for “The Philippines”

Aliases for “The Russian Federation”

Aliases for “Ascension And Tristan Da Cunha Saint Helena”

Aliases for “American Samoa”

Aliases for “Sao Tome And Principe”

Aliases for “South Georgia And The South Sandwich Islands”

Aliases for “The Republic Of Korea”

Aliases for “Saint Barthelemy”

Aliases for “Saint Kitts And Nevis”

Aliases for “Saint Lucia”

Aliases for “Dutch Part Sint Maarten”

Aliases for “French Part Saint Martin”

Aliases for “Saint Pierre And Miquelon”

Aliases for “Saint Vincent And The Grenadines”

Aliases for “The Sudan”

Aliases for “Taiwan Province Of China”

Aliases for “United Republic Of Tanzania”

Aliases for “Trinidad And Tobago”

Aliases for “The Turks And Caicos Islands”

Aliases for “The United Arab Emirates”

Aliases for “The United States Minor Outlying Islands”

Aliases for “Bolivarian Republic Of Venezuela”


Wrapper struct for alias tables to avoid using Box


Since reference for the EmptyLookupTable


A lookup table where all elements are statically known