#[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

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");

Equivalent to from_bytes(bytes[start..end]), but callable in a const context (which range indexing is not).

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(_)));

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");

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.

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 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");

The ULE type corresponding to Self. Read more

Converts from Self to Self::ULE. Read more

Converts from Self::ULE to Self. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Validates a byte slice, &[u8]. Read more

Parses a byte slice, &[u8], and return it as &[Self] with the same lifetime. Read more

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

Given &[Self], returns a &[u8] with the same lifetime. Read more

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

Returns a hint for the number of bytes that will be written to the sink. Read more

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

Creates a new String with the data from this Writeable. Like ToString, but smaller and faster. Read more

The container that can be used with this type: [ZeroVec] or [VarZeroVec].

The type produced by Container::get() Read more

The type produced by Container::replace() and Container::remove(), also used during deserialization. If Self is human readable serialized, deserializing to Self::OwnedType should produce the same value once passed through Self::owned_as_self() Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.