#[repr(transparent)]pub struct Region(_);
Expand description
A region subtag (examples: "US"
, "CN"
, "AR"
etc.)
Region
represents a Unicode base language code conformat to the
unicode_region_id
field of the Language and Locale Identifier.
Examples
use icu::locid::subtags::Region;
let region: Region = "DE".parse().expect("Failed to parse a region subtag.");
Implementations
sourceimpl Region
impl Region
sourcepub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError>
pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError>
sourcepub const fn from_bytes_manual_slice(
v: &[u8],
start: usize,
end: usize
) -> Result<Self, ParserError>
pub const fn from_bytes_manual_slice(
v: &[u8],
start: usize,
end: usize
) -> Result<Self, ParserError>
Equivalent to from_bytes(bytes[start..end])
,
but callable in a const
context (which range indexing is not).
sourcepub fn try_from_raw(v: [u8; 3]) -> Result<Self, ParserError>
pub fn try_from_raw(v: [u8; 3]) -> Result<Self, ParserError>
Safely creates a Region
from a reference to its raw format
as returned by Region::into_raw()
.
Examples
use icu::locid::subtags::Region;
assert!(matches!(Region::try_from_raw(*b"US\0"), Ok(_)));
assert!(matches!(Region::try_from_raw(*b"419"), Ok(_)));
assert!(matches!(Region::try_from_raw(*b"foo"), Err(_)));
assert!(matches!(Region::try_from_raw(*b"US0"), Err(_)));
// Unlike the other constructors, this one is case-sensitive:
assert!(matches!(Region::try_from_raw(*b"us\0"), Err(_)));
sourcepub fn into_raw(self) -> [u8; 3]
pub fn into_raw(self) -> [u8; 3]
Deconstructs the Region
into raw format to be consumed
by from_raw_unchecked()
.
Examples
use icu::locid::subtags::Region;
let region = Region::from_bytes(b"us").expect("Parsing failed.");
let raw = region.into_raw();
let region = unsafe { Region::from_raw_unchecked(raw) };
assert_eq!(region.as_str(), "US");
sourcepub const unsafe fn from_raw_unchecked(v: [u8; 3]) -> Self
pub const unsafe fn from_raw_unchecked(v: [u8; 3]) -> Self
Constructor which takes a raw value returned by
into_raw()
.
Examples
use icu::locid::subtags::Region;
let region = Region::from_bytes(b"us").expect("Parsing failed.");
let raw = region.into_raw();
let region = unsafe { Region::from_raw_unchecked(raw) };
assert_eq!(region.as_str(), "US");
Safety
This function accepts a [[u8; 3]
] that is expected to be a valid TinyAsciiStr<3>
representing a Region
subtag in canonical syntax.
sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
A helper function for displaying
a Region
subtag as a &
str
.
Examples
use icu::locid::subtags::Region;
let region = Region::from_bytes(b"it").expect("Parsing failed.");
assert_eq!(region.as_str(), "IT");
Notice
: For many use cases, such as comparison,
Region
implements PartialEq
<&
str
>
which allows for direct comparisons.
sourcepub fn is_alphabetic(&self) -> bool
pub fn is_alphabetic(&self) -> bool
Returns true if the Region has an alphabetic code.
Examples
use icu::locid::subtags::Region;
let region = Region::from_bytes(b"us").expect("Parsing failed.");
assert_eq!(region.is_alphabetic(), true);
sourcepub fn strict_cmp(&self, other: &[u8]) -> Ordering
pub fn strict_cmp(&self, other: &[u8]) -> Ordering
Compare this Region
with BCP-47 bytes.
The return value is equivalent to what would happen if you first converted this
Region
to a BCP-47 string and then performed a byte comparison.
This function is case-sensitive and results in a total order, so it is appropriate for
binary search. The only argument producing Ordering::Equal
is self.to_string()
.
sourcepub fn normalizing_eq(&self, other: &str) -> bool
pub fn normalizing_eq(&self, other: &str) -> bool
Compare this Region
with a potentially unnormalized BCP-47 string.
The return value is equivalent to what would happen if you first parsed the
BCP-47 string to a Region
and then performed a structucal comparison.
Trait Implementations
sourceimpl AsULE for Region
impl AsULE for Region
Impl enabling Region
to be used in a ZeroVec
. Enabled with the "zerovec"
feature.
Example
use icu::locid::subtags_region as region;
use icu::locid::subtags::Region;
use zerovec::ZeroVec;
let zv = ZeroVec::<Region>::parse_byte_slice(b"GB\0419001DE\0").expect("Valid region subtags");
assert_eq!(zv.get(1), Some(region!("419")));
ZeroVec::<Region>::parse_byte_slice(b"invalid").expect_err("Invalid byte slice");
sourceimpl Bake for Region
impl Bake for Region
sourcefn bake(&self, env: &CrateEnv) -> TokenStream
fn bake(&self, env: &CrateEnv) -> TokenStream
Returns a TokenStream
that would evalutate to self
. Read more
sourceimpl<'de> Deserialize<'de> for Region
impl<'de> Deserialize<'de> for Region
sourcefn 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
sourceimpl From<Region> for TinyAsciiStr<3>
impl From<Region> for TinyAsciiStr<3>
sourceimpl Ord for Region
impl Ord for Region
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialOrd<Region> for Region
impl PartialOrd<Region> for Region
sourcefn partial_cmp(&self, other: &Region) -> Option<Ordering>
fn partial_cmp(&self, other: &Region) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl ULE for Region
impl ULE for Region
sourcefn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>
fn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>
Validates a byte slice, &[u8]
. Read more
sourcefn parse_byte_slice(bytes: &[u8]) -> Result<&[Self], ZeroVecError>
fn parse_byte_slice(bytes: &[u8]) -> Result<&[Self], ZeroVecError>
Parses a byte slice, &[u8]
, and return it as &[Self]
with the same lifetime. Read more
sourceunsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &[Self]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &[Self]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
Takes a byte slice, &[u8]
, and return it as &[Self]
with the same lifetime, assuming
that this byte slice has previously been run through Self::parse_byte_slice()
with
success. Read more
sourceimpl Writeable for Region
impl Writeable for Region
sourcefn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
Writes bytes to the given sink. Errors from the sink are bubbled up.
The default implementation delegates to write_to_parts
, and discards any
Part
annotations. Read more
sourcefn write_len(&self) -> LengthHint
fn write_len(&self) -> LengthHint
Returns a hint for the number of bytes that will be written to the sink. Read more
sourcefn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error> where
S: PartsWrite + ?Sized,
fn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error> where
S: PartsWrite + ?Sized,
Write bytes and Part
annotations to the given sink. Errors from the
sink are bubbled up. The default implementation delegates to write_to
,
and doesn’t produce any Part
annotations. Read more
sourcefn write_to_string(&self) -> Cow<'_, str>
fn write_to_string(&self) -> Cow<'_, str>
Creates a new String
with the data from this Writeable
. Like ToString
,
but smaller and faster. Read more
sourceimpl<'a> ZeroMapKV<'a> for Region
impl<'a> ZeroMapKV<'a> for Region
impl Copy for Region
impl Eq for Region
impl StructuralEq for Region
impl StructuralPartialEq for Region
Auto Trait Implementations
impl RefUnwindSafe for Region
impl Send for Region
impl Sync for Region
impl Unpin for Region
impl UnwindSafe for Region
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more