pub struct Countries {
pub list: Vec<Country>,
}
Fields§
§list: Vec<Country>
Implementations§
Source§impl Countries
impl Countries
Sourcepub fn new() -> Self
pub fn new() -> Self
This is the constructor function.
#Example
extern crate scaffolding_core;
use scaffolding_core::*;
fn main() {
let countries = Countries::new();
}
Sourcepub fn is_valid(&self, country: Country) -> bool
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);
}
Sourcepub fn get_country_by_iso_2_code(&self, iso_2_code: String) -> Option<&Country>
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");
}
Sourcepub fn get_country_by_iso_3_code(&self, iso_3_code: String) -> Option<&Country>
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");
}
Sourcepub fn get_country_by_phone_code(&self, phone_code: String) -> Option<&Country>
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§
impl Freeze for Countries
impl RefUnwindSafe for Countries
impl Send for Countries
impl Sync for Countries
impl Unpin for Countries
impl UnwindSafe for Countries
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more