#[repr(transparent)]pub struct Variant(_);
Expand description
A variant subtag (examples: "macos"
, "posix"
, "1996"
etc.)
Variant
represents a Unicode base language code conformat to the
unicode_variant_id
field of the Language and Locale Identifier.
Examples
use icu::locid::subtags::Variant;
let variant: Variant = "macos".parse()
.expect("Failed to parse a variant subtag.");
Implementations
sourceimpl Variant
impl Variant
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; 8]) -> Result<Self, ParserError>
pub fn try_from_raw(v: [u8; 8]) -> Result<Self, ParserError>
Safely creates a Variant
from a reference to its raw format
as returned by Variant::into_raw()
.
Examples
use icu::locid::subtags::Variant;
assert!(matches!(Variant::try_from_raw(*b"fonipa\0\0"), Ok(_)));
assert!(matches!(Variant::try_from_raw(*b"1992\0\0\0\0"), Ok(_)));
assert!(matches!(Variant::try_from_raw(*b"foo\0\0\0\0\0"), Err(_)));
// Unlike the other constructors, this one is case-sensitive:
assert!(matches!(Variant::try_from_raw(*b"POSIX\0\0\0"), Err(_)));
sourcepub fn into_raw(self) -> [u8; 8]
pub fn into_raw(self) -> [u8; 8]
Deconstructs the Variant
into raw format to be consumed
by from_raw_unchecked()
.
Examples
use icu::locid::subtags::Variant;
let variant = Variant::from_bytes(b"posix")
.expect("Parsing failed.");
let raw = variant.into_raw();
let variant = unsafe { Variant::from_raw_unchecked(raw) };
assert_eq!(variant, "posix");
sourcepub const unsafe fn from_raw_unchecked(v: [u8; 8]) -> Self
pub const unsafe fn from_raw_unchecked(v: [u8; 8]) -> Self
Constructor which takes a raw value returned by
into_raw()
.
Examples
use icu::locid::subtags::Variant;
let variant = Variant::from_bytes(b"posix")
.expect("Parsing failed.");
let raw = variant.into_raw();
let variant = unsafe { Variant::from_raw_unchecked(raw) };
assert_eq!(variant, "posix");
Safety
This function accepts a [u8; 8] that is expected to be a valid TinyAsciiStr<8>
representing a Variant
subtag in canonical syntax.
sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
A helper function for displaying
a Variant
subtag as a &
str
.
Examples
use icu::locid::subtags::Variant;
let variant = Variant::from_bytes(b"macos")
.expect("Parsing failed.");
assert_eq!(variant.as_str(), "macos");
Notice
: For many use cases, such as comparison,
Variant
implements PartialEq
<&
str
>
which allows for direct comparisons.
Trait Implementations
sourceimpl AsULE for Variant
impl AsULE for Variant
Impl enabling Variant
to be used in a ZeroVec
. Enabled with the "zerovec"
feature.
Example
use icu::locid::subtags::Variant;
use icu::locid::variant;
use zerovec::ZeroVec;
let zv = ZeroVec::<Variant>::parse_byte_slice(b"fonipa\0\01992\0\0\0\0posix\0\0\0")
.expect("Valid variant subtags");
assert_eq!(zv.get(1), Some(variant!("1992")));
ZeroVec::<Variant>::parse_byte_slice(b"invalid")
.expect_err("Invalid byte slice");
sourceimpl<'de> Deserialize<'de> for Variant
impl<'de> Deserialize<'de> for Variant
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<Variant> for TinyAsciiStr<8>
impl From<Variant> for TinyAsciiStr<8>
sourceimpl Ord for Variant
impl Ord for Variant
sourceimpl PartialOrd<&'_ str> for Variant
impl PartialOrd<&'_ str> for Variant
sourcefn partial_cmp(&self, other: &&str) -> Option<Ordering>
fn partial_cmp(&self, other: &&str) -> 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 PartialOrd<Variant> for Variant
impl PartialOrd<Variant> for Variant
sourcefn partial_cmp(&self, other: &Variant) -> Option<Ordering>
fn partial_cmp(&self, other: &Variant) -> 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 Variant
impl ULE for Variant
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 &'_ [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 Variant
impl Writeable for Variant
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 Variant
impl<'a> ZeroMapKV<'a> for Variant
type Container = ZeroVec<'a, Variant>
type Container = ZeroVec<'a, Variant>
The container that can be used with this type: ZeroVec
or VarZeroVec
.
impl Copy for Variant
impl Eq for Variant
impl StructuralEq for Variant
impl StructuralPartialEq for Variant
Auto Trait Implementations
impl RefUnwindSafe for Variant
impl Send for Variant
impl Sync for Variant
impl Unpin for Variant
impl UnwindSafe for Variant
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