countriex

Crates.iocountriex
lib.rscountriex
version0.1.1
sourcesrc
created_at2023-04-28 20:32:01.684639
updated_at2023-04-29 01:55:34.177075
descriptionCountriex is a Rust library that provides information about countries around the world. It includes data on a wide range of topics, including population, location, and official languages. It includes data from ISO 3166 (countries and states/subdivisions), ISO 4217 (currency), and E.164 (phone numbers).
homepage
repository
max_upload_size
id851693
size163,155
Webster Avosa (avosa)

documentation

README

Countriex

Countriex is a Rust library that provides information about countries around the world. It includes data on a wide range of topics, including population, location, and official languages. It includes data from ISO 3166 (countries and states/subdivisions), ISO 4217 (currency), and E.164 (phone numbers).

Usage

To use the Countriex library in your Rust project, add the following line to your Cargo.toml file:

[dependencies]
countriex = "0.1.0"

Then, import the library into your Rust code using the use keyword:

use countriex::{all, get_by, filter};

Examples

use countriex::{all, get_by, filter};

fn main() {
    // Get the total number of countries
    let total_countries = all();
    println!("Number of countries: {:?}", total_countries);

    // Find a country by its 2-letter ISO code (alpha2)
    let country_alpha2 = get_by("alpha2", "US");
    println!("Country by alpha2: {:?}", country_alpha2);

    // Find a country by its 3-letter ISO code (alpha3)
    let country_alpha3 = get_by("alpha3", "USA");
    println!("Country by alpha3: {:?}", country_alpha3);

    // Find a country by its common name
    let country_name = get_by("name", "United States");
    println!("Country by name: {:?}", country_name);

    // Find all countries in a specific continent
    let countries_in_asia = filter("continent", "Asia");
    println!("Countries in Asia: {:?}", countries_in_asia);

    // Find all countries in a specific region
    let countries_in_southern_europe = filter("region", "Southern Europe");
    println!("Countries in Southern Europe: {:?}", countries_in_southern_europe);

    // Find all EU member countries
    let eu_member_countries = filter("eu_member", "true");
    println!("EU member countries: {:?}", eu_member_countries);
}

Functions

Countriex provides the following functions:

  • all(): Returns the total number of countries.
  • get_by(key: &str, value: &str) -> Option<Country>: Returns the first matching country with the given criteria, or None if a country with that data does not exist.
  • filter(key: &str, value: &str) -> Vec<Country>: Returns all countries matching the given criteria, or [] if the criteria does not match any countries.

Credits

This library uses data from the restcountries API.

Commit count: 0

cargo fmt