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 oregon: RegionCode = "OR".parse().unwrap();
assert_eq!(oregon.to_string(), "OR");
let valley: RegionCode = "Rogue Valley".parse().unwrap();
assert_eq!(valley.to_string(), "0xC0F9");Implementations§
Source§impl RegionCode
impl RegionCode
Sourcepub const fn from_bytes(bytes: [u8; 2]) -> Self
pub const fn from_bytes(bytes: [u8; 2]) -> Self
Wrap a code from its two wire bytes.
Sourcepub fn from_short_code(code: &str) -> Result<Self, RegionCodeError>
pub fn from_short_code(code: &str) -> Result<Self, RegionCodeError>
Encode a short code: one to three ASCII letters or digits.
Case-insensitive. Anything longer, or bearing a character ARNCE spells but a region may not use, is rejected, so that named regions cannot be mistaken for short codes.
An all-letter code is exclusive — no named region can derive it — and so reads back as itself. One bearing a digit encodes just as faithfully but shares its space with the hashes, so it does not.
Sourcepub fn from_name(name: &str) -> Self
pub fn from_name(name: &str) -> Self
Derive the code for a named region.
ASCII letters are folded to lowercase before hashing, so spellings that differ only in case are the same region. No other bytes are altered; a name containing non-ASCII characters hashes those bytes verbatim.
Sourcepub fn letters(self) -> Option<Letters>
pub fn letters(self) -> Option<Letters>
Return the letters this code decodes to, if it decodes to letters at all.
Some means the code came from an all-letter
short code: named regions are transformed
out of this space by construction. A code decoding to anything else,
digits included, has no reading and returns None.
Trait Implementations§
Source§impl Clone for RegionCode
impl Clone for RegionCode
Source§fn clone(&self) -> RegionCode
fn clone(&self) -> RegionCode
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RegionCode
impl Debug for RegionCode
Source§impl Display for RegionCode
impl Display for RegionCode
Source§impl From<RegionCode> for [u8; 2]
impl From<RegionCode> for [u8; 2]
Source§fn from(code: RegionCode) -> Self
fn from(code: RegionCode) -> Self
Source§impl FromStr for RegionCode
Parse a region code from its textual form.
impl FromStr for RegionCode
Parse a region code from its textual form.
0x followed by exactly four hex digits is the code it spells, one to
three ASCII letters or digits is a short code, and anything else is a
region name. The derivation is total over every string of one to
REGION_NAME_MAX_LEN bytes: a string that merely looks like a literal
code — 0x12, 0xzz — is not one, and is hashed as the name it is
(packet-options.md § Region Code Encoding).
Source§impl Hash for RegionCode
impl Hash for RegionCode
Source§impl Ord for RegionCode
impl Ord for RegionCode
Source§impl PartialEq for RegionCode
impl PartialEq for RegionCode
Source§impl PartialOrd for RegionCode
impl PartialOrd for RegionCode
impl Copy for RegionCode
impl Eq for RegionCode
impl StructuralPartialEq for RegionCode
Auto Trait Implementations§
impl Freeze for RegionCode
impl RefUnwindSafe for RegionCode
impl Send for RegionCode
impl Sync for RegionCode
impl Unpin for RegionCode
impl UnwindSafe for RegionCode
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)