Struct Countries

Source
pub struct Countries {
    pub list: Vec<Country>,
}

Fields§

§list: Vec<Country>

Implementations§

Source§

impl Countries

Source

pub fn new() -> Self

This is the constructor function.

#Example

extern crate scaffolding_core;

use scaffolding_core::*;

fn main() {
  let countries = Countries::new();
}
Source

pub fn is_valid(&self, country: Country) -> bool

Verifies a Country

§Example
extern crate scaffolding_core;

use scaffolding_core::*;

fn main() {
 let countries = Countries::new();
  let country = Country::new(
      "United States".to_string(),
      "1".to_string(),
      "US".to_string(),
      "USA".to_string()
  );

  assert_eq!(countries.is_valid(country), true);
}
Source

pub fn get_country_by_iso_2_code(&self, iso_2_code: String) -> Option<&Country>

Retrieves a Country based on the ISO 2 Code

§Example
extern crate scaffolding_core;

use scaffolding_core::*;

fn main() {
 let countries = Countries::new();
 let country = countries.get_country_by_iso_2_code("US".to_string()).unwrap();

 assert_eq!(country.name, "United States");
 assert_eq!(country.phone_code, "1");
 assert_eq!(country.iso_2_code, "US");
 assert_eq!(country.iso_3_code, "USA");
}
Source

pub fn get_country_by_iso_3_code(&self, iso_3_code: String) -> Option<&Country>

Retrieves a Country based on the ISO 3 Code

§Example
extern crate scaffolding_core;

use scaffolding_core::*;

fn main() {
 let countries = Countries::new();
 let country = countries.get_country_by_iso_3_code("USA".to_string()).unwrap();

 assert_eq!(country.name, "United States");
 assert_eq!(country.phone_code, "1");
 assert_eq!(country.iso_2_code, "US");
 assert_eq!(country.iso_3_code, "USA");
}
Source

pub fn get_country_by_phone_code(&self, phone_code: String) -> Option<&Country>

Retrieves a Country based on the international phone code

§Example
extern crate scaffolding_core;

use scaffolding_core::*;

fn main() {
 let countries = Countries::new();
 let country = countries.get_country_by_phone_code("1".to_string()).unwrap();

 assert_eq!(country.name, "United States");
 assert_eq!(country.phone_code, "1");
 assert_eq!(country.iso_2_code, "US");
 assert_eq!(country.iso_3_code, "USA");
}

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> 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, 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.