RegionCode

Struct RegionCode 

Source
pub struct RegionCode(/* private fields */);
Expand description

A 2-byte region identifier.

let sjc: RegionCode = "SJC".parse().unwrap();
assert_eq!(sjc.to_bytes(), [0x78, 0x53]);
assert_eq!(sjc.to_string(), "SJC");

let valley: RegionCode = "Rogue Valley".parse().unwrap();
assert_eq!(valley.to_string(), "0xDF6F");

Implementations§

Source§

impl RegionCode

Source

pub const fn from_u16(value: u16) -> Self

Wrap a raw code.

Source

pub const fn as_u16(self) -> u16

Return the raw code.

Source

pub const fn from_bytes(bytes: [u8; 2]) -> Self

Wrap a code from its two wire bytes.

Source

pub const fn to_bytes(self) -> [u8; 2]

Return the code’s two wire bytes.

Source

pub fn from_iata(code: &str) -> Result<Self, RegionCodeError>

Encode a 3-letter IATA airport code.

Case-insensitive. Anything that is not exactly three ASCII letters is rejected, so that named regions cannot be mistaken for airports.

Source

pub fn from_name(name: &str) -> Self

Derive the code for a named region.

The name is hashed verbatim, so callers that want names to compare equal across operators must agree on the exact spelling.

Source

pub fn letters(self) -> Option<[u8; 3]>

Return the three letters this code decodes to, if it decodes to three letters at all.

Some means the code came from from_iata: named regions are transformed out of this space by construction.

Trait Implementations§

Source§

impl Clone for RegionCode

Source§

fn clone(&self) -> RegionCode

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RegionCode

Source§

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

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

impl Display for RegionCode

Source§

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

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

impl From<[u8; 2]> for RegionCode

Source§

fn from(bytes: [u8; 2]) -> Self

Converts to this type from the input type.
Source§

impl From<RegionCode> for [u8; 2]

Source§

fn from(code: RegionCode) -> Self

Converts to this type from the input type.
Source§

impl FromStr for RegionCode

Parse a region code from its textual form.

Three ASCII letters are an IATA code, 0xXXXX is a raw code, and anything else is a region name.

Source§

type Err = RegionCodeError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for RegionCode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for RegionCode

Source§

fn cmp(&self, other: &RegionCode) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for RegionCode

Source§

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

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

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 PartialOrd for RegionCode

Source§

fn partial_cmp(&self, other: &RegionCode) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for RegionCode

Source§

impl Eq for RegionCode

Source§

impl StructuralPartialEq for RegionCode

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.