Struct icu::locid::subtags::Language[][src]

pub struct Language(_);

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

impl Language[src]

pub fn from_bytes(v: &[u8]) -> Result<Language, ParserError>[src]

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

pub fn into_raw(self) -> Option<u32>[src]

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

pub const unsafe fn from_raw_unchecked(v: Option<u32>) -> Language[src]

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.

pub const fn und() -> Language[src]

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

pub fn as_str(&self) -> &str[src]

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.

pub fn clear(&mut self)[src]

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

pub fn is_empty(self) -> bool[src]

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

impl Clone for Language[src]

impl Copy for Language[src]

impl Debug for Language[src]

impl Default for Language[src]

impl Display for Language[src]

impl Eq for Language[src]

impl FromStr for Language[src]

type Err = ParserError

The associated error which can be returned from parsing.

impl Hash for Language[src]

impl Ord for Language[src]

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

impl PartialEq<Language> for Language[src]

impl PartialOrd<Language> for Language[src]

impl StructuralEq for Language[src]

impl StructuralPartialEq for Language[src]

impl Writeable for Language[src]

Auto Trait Implementations

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> ErasedDataStruct for T where
    T: Clone + Debug + Any

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.