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
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.
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.
Trait Implementations
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
Auto Trait Implementations
impl RefUnwindSafe for Language
impl UnwindSafe for Language
Blanket Implementations
Mutably borrows from an owned value. Read more