Struct Country

Source
pub struct Country {
    pub name: &'static str,
    pub capital: Option<&'static str>,
    pub region: Option<&'static str>,
    pub alpha_2: &'static str,
    pub alpha_3: &'static str,
    pub timezones: &'static [Timezone],
    pub currencies: &'static [Currency],
    pub languages: &'static [Language],
    pub call_codes: &'static [&'static str],
}
Expand description

Represents a Country.

Fields§

§name: &'static str

Name of the country, eg. “United States”.

§capital: Option<&'static str>

Name of the country’s capital, eg. “Washington, DC”.

§region: Option<&'static str>

Region of the country

§alpha_2: &'static str

ISO 3166-1 2-letter country code

§alpha_3: &'static str

3166-1 3-letter country code

§timezones: &'static [Timezone]

Timezones that country has in UTC, eg. UTC-05:00 for columbia

§currencies: &'static [Currency]

Currencies used in the country

§languages: &'static [Language]

Languages used in the country

§call_codes: &'static [&'static str]

Dialling codes used in a country

Implementations§

Source§

impl Country

Source

pub fn from_name(name: &str) -> Option<&'static Self>

Get the country from it’s name

§Example
use iso_rs::prelude::*;

let country = Country::from_name("India").unwrap();
assert_eq!(country.capital.unwrap(), "New Delhi");
Source

pub fn from_capital(capital: &str) -> Option<&'static [Self]>

Get a list of countries from a capital

§Example
use iso_rs::prelude::*;

let country = Country::from_capital("New Delhi").unwrap()[0];
assert_eq!(country.name, "India");
Source

pub fn from_region(region: &str) -> Option<&'static [Self]>

Get a list of countries inside a region

§Example
use iso_rs::prelude::*;

let southern_asia = Country::from_region("Southern Asia").unwrap();
assert!(southern_asia.contains(Country::from_name("India").unwrap()));
Source

pub fn from_alpha_2(alpha_2: &str) -> Option<&'static [Self]>

Get the country from its ISO 3166-1 alpha_2 code

§Example
use iso_rs::prelude::*;

let mut country = Country::from_alpha_2("IN").unwrap();
assert_eq!(country[0], *Country::from_name("India").unwrap());
Source

pub fn from_alpha_3(alpha_3: &str) -> Option<&'static [Self]>

Get the country from its ISO 3166-1 alpha_3 code

§Example
use iso_rs::prelude::*;

let mut country = Country::from_alpha_3("IND").unwrap();
assert_eq!(country[0], *Country::from_name("India").unwrap());

Trait Implementations§

Source§

impl Clone for Country

Source§

fn clone(&self) -> Country

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Country

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Country

Source§

fn eq(&self, other: &Country) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Country

Source§

impl Eq for Country

Source§

impl StructuralPartialEq for Country

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.