#[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<Region, ParserError>
pub const fn from_bytes(v: &[u8]) -> Result<Region, ParserError>
sourcepub const fn from_bytes_manual_slice(
v: &[u8],
start: usize,
end: usize
) -> Result<Region, ParserError>
pub const fn from_bytes_manual_slice(
v: &[u8],
start: usize,
end: usize
) -> Result<Region, 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<Region, ParserError>
pub fn try_from_raw(v: [u8; 3]) -> Result<Region, 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, "US");
sourcepub const unsafe fn from_raw_unchecked(v: [u8; 3]) -> Region
pub const unsafe fn from_raw_unchecked(v: [u8; 3]) -> Region
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, "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);
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;
use icu::locid::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<'de> Deserialize<'de> for Region
impl<'de> Deserialize<'de> for Region
sourcefn deserialize<D>(
deserializer: D
) -> Result<Region, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<Region, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Ord for Region
impl Ord for Region
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 Serialize for Region
impl Serialize for Region
sourcefn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. 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
fn 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
unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &[Self]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &[Self]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [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>(&self, sink: &mut W) -> Result<(), Error> where
W: Write + ?Sized,
fn write_to<W>(&self, sink: &mut W) -> Result<(), Error> where
W: Write + ?Sized,
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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more