pub struct Variant(/* private fields */);
Expand description
A variant subtag (examples: "macos"
, "posix"
, "1996"
etc.)
Variant
represents a Unicode base language code conformant to the
unicode_variant_id
field of the Language and Locale Identifier.
§Examples
use icu::locale::subtags::Variant;
let variant: Variant =
"macos".parse().expect("Failed to parse a variant subtag.");
Implementations§
source§impl Variant
impl Variant
sourcepub const fn try_from_str(s: &str) -> Result<Variant, ParseError>
pub const fn try_from_str(s: &str) -> Result<Variant, ParseError>
sourcepub const fn try_from_utf8(code_units: &[u8]) -> Result<Variant, ParseError>
pub const fn try_from_utf8(code_units: &[u8]) -> Result<Variant, ParseError>
sourcepub const fn try_from_raw(raw: [u8; 8]) -> Result<Variant, ParseError>
pub const fn try_from_raw(raw: [u8; 8]) -> Result<Variant, ParseError>
Safely creates a Variant
from its raw format
as returned by Self::into_raw
. Unlike Self::try_from_utf8
,
this constructor only takes normalized values.
sourcepub const unsafe fn from_raw_unchecked(v: [u8; 8]) -> Variant
pub const unsafe fn from_raw_unchecked(v: [u8; 8]) -> Variant
Unsafely creates a Variant
from its raw format
as returned by Self::into_raw
. Unlike Self::try_from_utf8
,
this constructor only takes normalized values.
§Safety
This function is safe iff Self::try_from_raw
returns an Ok
. This is the case
for inputs that are correctly normalized.
sourcepub const fn into_raw(self) -> [u8; 8]
pub const fn into_raw(self) -> [u8; 8]
Deconstructs into a raw format to be consumed by
from_raw_unchecked
or
try_from_raw
.
sourcepub fn strict_cmp(self, other: &[u8]) -> Ordering
pub fn strict_cmp(self, other: &[u8]) -> Ordering
Compare with BCP-47 bytes.
The return value is equivalent to what would happen if you first converted
self
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.as_str().as_bytes()
.
sourcepub fn normalizing_eq(self, other: &str) -> bool
pub fn normalizing_eq(self, other: &str) -> bool
Compare with a potentially unnormalized BCP-47 string.
The return value is equivalent to what would happen if you first parsed the BCP-47 string and then performed a structural comparison.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Variant
impl<'de> Deserialize<'de> for Variant
source§fn deserialize<D>(
deserializer: D,
) -> Result<Variant, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Variant, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
source§impl Display for Variant
impl Display for Variant
This trait is implemented for compatibility with fmt!
.
To create a string, [Writeable::write_to_string
] is usually more efficient.
source§impl From<Variant> for TinyAsciiStr<8>
impl From<Variant> for TinyAsciiStr<8>
source§fn from(input: Variant) -> TinyAsciiStr<8>
fn from(input: Variant) -> TinyAsciiStr<8>
source§impl NicheBytes<8> for Variant
impl NicheBytes<8> for Variant
const NICHE_BIT_PATTERN: [u8; 8] = tinystr::TinyAsciiStr<8>::NICHE_BIT_PATTERN
source§impl Ord for Variant
impl Ord for Variant
source§impl PartialOrd for Variant
impl PartialOrd for Variant
source§impl Serialize for Variant
impl Serialize for Variant
source§fn 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,
source§impl ULE for Variant
impl ULE for Variant
source§fn validate_bytes(bytes: &[u8]) -> Result<(), UleError>
fn validate_bytes(bytes: &[u8]) -> Result<(), UleError>
&[u8]
. Read moresource§unsafe fn slice_from_bytes_unchecked(bytes: &[u8]) -> &[Self]
unsafe fn slice_from_bytes_unchecked(bytes: &[u8]) -> &[Self]
&[u8]
, and return it as &[Self]
with the same lifetime, assuming
that this byte slice has previously been run through Self::parse_bytes_to_slice()
with
success. Read moresource§impl Writeable for Variant
impl Writeable for Variant
source§fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>
fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>
write_to_parts
, and discards any
Part
annotations.source§fn writeable_length_hint(&self) -> LengthHint
fn writeable_length_hint(&self) -> LengthHint
source§fn write_to_string(&self) -> Cow<'_, str>
fn write_to_string(&self) -> Cow<'_, str>
String
with the data from this Writeable
. Like ToString
,
but smaller and faster. Read moresource§fn 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,
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.source§impl<'a> ZeroMapKV<'a> for Variant
impl<'a> ZeroMapKV<'a> for Variant
impl Copy for Variant
impl Eq for Variant
impl StructuralPartialEq for Variant
Auto Trait Implementations§
impl Freeze for Variant
impl RefUnwindSafe for Variant
impl Send for Variant
impl Sync for Variant
impl Unpin for Variant
impl UnwindSafe for Variant
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more