pub struct IsoCountry(/* private fields */);Expand description
ISO-3166-1 alpha-2 country code (e.g. US, GB, PK).
Validated on construction so a downstream validator never has to
reject malformed strings. Stored upper-case for stable hashing and
serde output; comparisons are case-insensitive at the boundary via
IsoCountry::eq_ignore_ascii_case.
§Example
use stygian_proxy::ports::coherence::IsoCountry;
let us = IsoCountry::new("us").unwrap();
assert_eq!(us.as_str(), "US");
assert!(IsoCountry::new("USA").is_none());
assert!(IsoCountry::new("u").is_none());Implementations§
Source§impl IsoCountry
impl IsoCountry
Sourcepub fn new(raw: &str) -> Option<Self>
pub fn new(raw: &str) -> Option<Self>
Parse and uppercase a two-letter country code.
Returns None when raw is not exactly two ASCII alpha
characters; the validator treats unknown / malformed codes as
CoherenceVerdict::Unknown rather than emitting false
mismatches.
Sourcepub fn eq_ignore_ascii_case(&self, other: &str) -> bool
pub fn eq_ignore_ascii_case(&self, other: &str) -> bool
Case-insensitive equality check for inbound config that may not have been normalised.
§Example
use stygian_proxy::ports::coherence::IsoCountry;
let us = IsoCountry::new("US").unwrap();
assert!(us.eq_ignore_ascii_case("us"));
assert!(us.eq_ignore_ascii_case("Us"));
assert!(!us.eq_ignore_ascii_case("GB"));Trait Implementations§
Source§impl Clone for IsoCountry
impl Clone for IsoCountry
Source§fn clone(&self) -> IsoCountry
fn clone(&self) -> IsoCountry
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for IsoCountry
impl Debug for IsoCountry
Source§impl<'de> Deserialize<'de> for IsoCountry
impl<'de> Deserialize<'de> for IsoCountry
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 Display for IsoCountry
impl Display for IsoCountry
impl Eq for IsoCountry
Source§impl Hash for IsoCountry
impl Hash for IsoCountry
Source§impl PartialEq for IsoCountry
impl PartialEq for IsoCountry
Source§impl Serialize for IsoCountry
impl Serialize for IsoCountry
impl StructuralPartialEq for IsoCountry
Auto Trait Implementations§
impl Freeze for IsoCountry
impl RefUnwindSafe for IsoCountry
impl Send for IsoCountry
impl Sync for IsoCountry
impl Unpin for IsoCountry
impl UnsafeUnpin for IsoCountry
impl UnwindSafe for IsoCountry
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.