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]
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]
Trait Implementations
impl PartialOrd<Language> for Language
[src]
impl PartialOrd<Language> for Language
[src]pub fn partial_cmp(&self, other: &Language) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq for Language
[src]
impl StructuralEq for Language
[src]impl StructuralPartialEq for Language
[src]
impl StructuralPartialEq for Language
[src]Auto Trait Implementations
impl RefUnwindSafe for Language
impl RefUnwindSafe for Language
impl UnwindSafe for Language
impl UnwindSafe for Language