Struct icu_locid::subtags::Variant [−][src]
pub struct Variant(_);
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
impl Variant
[src]
impl Variant
[src]pub fn from_bytes(v: &[u8]) -> Result<Self, ParserError>
[src]
A constructor which takes a utf8 slice, parses it and
produces a well-formed Variant
.
Examples
use icu::locid::subtags::Variant; let variant = Variant::from_bytes(b"posix") .expect("Parsing failed."); assert_eq!(variant, "posix");
pub fn into_raw(self) -> u64
[src]
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");
pub const unsafe fn from_raw_unchecked(v: u64) -> Self
[src]
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 u64
that is expected to be a valid TinyStr8
representing a Variant
subtag in canonical syntax.
pub fn as_str(&self) -> &str
[src]
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
impl PartialOrd<Variant> for Variant
[src]
impl PartialOrd<Variant> for Variant
[src]impl StructuralEq for Variant
[src]
impl StructuralEq for Variant
[src]impl StructuralPartialEq for Variant
[src]
impl StructuralPartialEq for Variant
[src]Auto Trait Implementations
impl RefUnwindSafe for Variant
impl RefUnwindSafe for Variant
impl UnwindSafe for Variant
impl UnwindSafe for Variant