pub struct Alpha3(/* private fields */);Expand description
A wrapper around the numeric enumeration requiring strings be Alpha-2 format.
When the serde feature is enabled, this type will be serialized as the Alpha-3 string.
§Examples
use iso3166_static::Alpha3;
const ALPHA3_USA: &str = "USA";
let alpha3 = Alpha3::from_alpha3(ALPHA3_USA).expect("valid alpha3");
assert_eq!(ALPHA3_USA, alpha3.as_str());Implementations§
Source§impl Alpha3
impl Alpha3
Sourcepub const fn from_alpha3(s: &str) -> Result<Self, Error>
pub const fn from_alpha3(s: &str) -> Result<Self, Error>
Create a new value from an Alpha2 string.
This method strictly validates the given slice and only accepts valid upper-case Alpha3 codes with no padding.
§Errors
Error::InvalidLengthif the given slice is not 3 characters.Error::InvalidCharsetif the given slice contains non-ASCII-7 characters.Error::UnknownStringif the given slice does not match any known Alpha3 code.
Sourcepub const fn from_u16(value: u16) -> Result<Self, Error>
pub const fn from_u16(value: u16) -> Result<Self, Error>
Create a new value from an unsigned integer.
§Errors
Error::UnknownCodeif the given code value is not a numeric code.
Sourcepub const fn from_alpha2(value: Alpha2) -> Self
pub const fn from_alpha2(value: Alpha2) -> Self
Create a new value from an Alpha2 code.
Sourcepub const fn from_numeric(value: Numeric) -> Self
pub const fn from_numeric(value: Numeric) -> Self
Create a new value from a numeric code.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Alpha3
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Alpha3
Available on crate feature
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Alpha3
impl Ord for Alpha3
Source§impl PartialOrd for Alpha3
impl PartialOrd for Alpha3
impl Copy for Alpha3
impl Eq for Alpha3
impl StructuralPartialEq for Alpha3
Auto Trait Implementations§
impl Freeze for Alpha3
impl RefUnwindSafe for Alpha3
impl Send for Alpha3
impl Sync for Alpha3
impl Unpin for Alpha3
impl UnwindSafe for Alpha3
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