Crates.io | nationify |
lib.rs | nationify |
version | 0.1.1 |
source | src |
created_at | 2024-12-09 19:12:15.04344 |
updated_at | 2024-12-09 19:27:39.048086 |
description | A library that provide information about countries |
homepage | |
repository | https://github.com/mohamadzoh/nationify |
max_upload_size | |
id | 1477734 |
size | 326,144 |
Nationify is a Rust library designed for querying and managing country-related data. It provides an intuitive interface for retrieving information such as ISO codes, names, regions, languages, and geographical data.
Add nationify
as a dependency in your Cargo.toml
:
[dependencies]
nationify = "0.1.1"
Get a list of all country ISO codes.
use nationify::iso_codes;
fn main() {
let codes = iso_codes();
println!("ISO Codes: {:?}", codes);
}
Fetch all country names.
use nationify::country_names;
fn main() {
let names = country_names();
println!("Country Names: {:?}", names);
}
Find a country by its ISO code or name.
use nationify::{by_iso_code, by_country_name};
fn main() {
if let Some(country) = by_iso_code("US") {
println!("Country by ISO Code: {:?}", country);
}
if let Some(country) = by_country_name("United States") {
println!("Country by Name: {:?}", country);
}
}
Perform case-insensitive searches for countries.
use nationify::by_country_name_or_code_case_insensitive;
fn main() {
if let Some(country) = by_country_name_or_code_case_insensitive("united states") {
println!("Case-Insensitive Search: {:?}", country);
}
}
Fetch a list of unique continents, regions, or subregions.
use nationify::{continents, regions, world_subregions};
fn main() {
println!("Continents: {:?}", continents());
println!("Regions: {:?}", regions());
println!("Subregions: {:?}", world_subregions());
}
Filter countries by specific geographical areas.
use nationify::{by_region, by_continent, by_subregion};
fn main() {
let african_countries = by_region("Africa");
println!("Countries in Africa: {:?}", african_countries);
let asian_countries = by_continent("Asia");
println!("Countries in Asia: {:?}", asian_countries);
let subregion_countries = by_subregion("Northern Europe");
println!("Countries in Northern Europe: {:?}", subregion_countries);
}
Search countries based on official or spoken languages.
use nationify::{by_languages_official, by_languages_spoken};
fn main() {
let english_official = by_languages_official("English");
println!("Countries where English is an official language: {:?}", english_official);
let english_spoken = by_languages_spoken("English");
println!("Countries where English is spoken: {:?}", english_spoken);
}
Access detailed metadata for countries.
use nationify::by_country_name;
fn main() {
if let Some(country) = by_country_name("United States") {
println!("ISO Code: {}", country.iso_code);
println!("Continent: {}", country.continent);
println!("Region: {}", country.region);
println!("Subregion: {}", country.subregion);
println!("Official Languages: {:?}", country.languages_official);
println!("Spoken Languages: {:?}", country.languages_spoken);
}
}
Country
The Country
struct provides comprehensive details for each country.
#[derive(Debug, Clone, PartialEq)]
pub struct Country<'a> {
pub iso_code: &'a str,
pub alpha3: &'a str,
pub continent: &'a str,
pub region: &'a str,
pub subregion: &'a str,
pub languages_official: &'a [&'a str],
pub languages_spoken: &'a [&'a str],
pub geo: Geo,
// ... additional fields
}
Geo
and Bounds
Geographical data includes latitude, longitude, and boundary information.
Rusty Rails is a larger project aiming to bridge the gap between Rust and Ruby/Ruby on Rails. We are actively working on recreating ruby library into rust that seamlessly make working in rust more easy and fun for new developers.
Contributions to the Phonelib library are welcome! Feel free to open issues, submit pull requests, or provide feedback to help improve this library.