Struct icu_locid::subtags::Language[][src]

pub struct Language(_);
Expand description

A language subtag (examples: "en", "csb", "zh", "und", etc.)

Language represents a Unicode base language code conformat to the unicode_language_id field of the Language and Locale Identifier.

Examples

use icu::locid::subtags::Language;

let language: Language = "en".parse()
    .expect("Failed to parse a language subtag.");

If the Language has no value assigned, it serializes to a string "und", which can be then parsed back to an empty Language field.

Examples

use icu::locid::subtags::Language;

assert_eq!(Language::default().as_str(), "und");

Notice: ICU4X uses a narrow form of language subtag of 2-3 characters. The specification allows language subtag to optionally also be 5-8 characters but that form has not been used and ICU4X does not support it right now.

Implementations

A constructor which takes a utf8 slice, parses it and produces a well-formed Language.

Examples

use icu::locid::subtags::Language;

let lang = Language::from_bytes(b"en")
    .expect("Parsing failed.");

assert_eq!(lang, "en");

Deconstructs the Language into raw format to be consumed by from_raw_unchecked().

Examples

use icu::locid::subtags::Language;

let lang = Language::from_bytes(b"en")
    .expect("Parsing failed.");

let raw = lang.into_raw();
let lang = unsafe { Language::from_raw_unchecked(raw) };
assert_eq!(lang, "en");

Constructor which takes a raw value returned by into_raw().

Examples

use icu::locid::subtags::Language;

let lang = Language::from_bytes(b"en")
    .expect("Parsing failed.");

let raw = lang.into_raw();
let lang = unsafe { Language::from_raw_unchecked(raw) };
assert_eq!(lang, "en");

Safety

This function accepts a u32 that is expected to be a valid TinyStr4 representing a Language subtag in canonical syntax.

Returns the default undefined language “und”. Same as default(), but is const.

Examples

use icu::locid::subtags::Language;

const language: Language = Language::und();
assert_eq!(Language::default(), language);
assert_eq!("und", language.to_string());

A helper function for displaying a Language subtag as a &str.

Examples

use icu::locid::subtags::Language;

let lang = Language::from_bytes(b"en")
    .expect("Parsing failed.");

assert_eq!(lang.as_str(), "en");

Notice: For many use cases, such as comparison, Language implements PartialEq<&str> which allows for direct comparisons.

Resets the Language subtag to an empty one.

Examples

use icu::locid::subtags::Language;

let mut lang: Language = "csb".parse()
    .expect("Parsing failed.");

assert_eq!(lang.as_str(), "csb");

lang.clear();

assert_eq!(lang.as_str(), "und");

Tests if the Language subtag is empty.

Examples

use icu::locid::subtags::Language;

let mut lang: Language = "und".parse()
    .expect("Parsing failed.");

assert_eq!(lang.is_empty(), true);

lang.clear();

assert_eq!(lang.is_empty(), true);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

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

Writes bytes to the given sink. Errors from the sink are bubbled up.

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

Creates a new String with the data from this Writeable. Like ToString, but smaller and faster. 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

Performs the conversion.

Performs the conversion.

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)

recently added

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.