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]

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 Clone for Variant[src]

impl Copy for Variant[src]

impl Debug for Variant[src]

impl Display for Variant[src]

impl Eq for Variant[src]

impl FromStr for Variant[src]

type Err = ParserError

The associated error which can be returned from parsing.

impl Hash for Variant[src]

impl Ord for Variant[src]

impl PartialEq<&'_ str> for Variant[src]

impl PartialEq<Variant> for Variant[src]

impl PartialEq<str> for Variant[src]

impl PartialOrd<Variant> for Variant[src]

impl StructuralEq for Variant[src]

impl StructuralPartialEq for Variant[src]

impl Writeable for Variant[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.