pub struct Language(/* private fields */);Expand description
A language subtag (examples: "en", "csb", "zh", "und", etc.)
Language represents a Unicode base language code conformant to the
unicode_language_id field of the Language and Locale Identifier.
§Examples
use icu::locale::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::locale::subtags::Language;
assert_eq!(Language::UNKNOWN.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§
Source§impl Language
 
impl Language
Sourcepub const fn try_from_str(s: &str) -> Result<Language, ParseError>
 
pub const fn try_from_str(s: &str) -> Result<Language, ParseError>
Sourcepub const fn try_from_utf8(code_units: &[u8]) -> Result<Language, ParseError>
 
pub const fn try_from_utf8(code_units: &[u8]) -> Result<Language, ParseError>
Sourcepub const fn try_from_raw(raw: [u8; 3]) -> Result<Language, ParseError>
 
pub const fn try_from_raw(raw: [u8; 3]) -> Result<Language, ParseError>
Safely creates a Language from its raw format
as returned by Self::into_raw. Unlike Self::try_from_utf8,
this constructor only takes normalized values.
Sourcepub const unsafe fn from_raw_unchecked(v: [u8; 3]) -> Language
 
pub const unsafe fn from_raw_unchecked(v: [u8; 3]) -> Language
Unsafely creates a Language from its raw format
as returned by Self::into_raw. Unlike Self::try_from_utf8,
this constructor only takes normalized values.
§Safety
This function is safe iff Self::try_from_raw returns an Ok. This is the case
for inputs that are correctly normalized.
Sourcepub const fn into_raw(self) -> [u8; 3]
 
pub const fn into_raw(self) -> [u8; 3]
Deconstructs into a raw format to be consumed by
from_raw_unchecked or
try_from_raw.
Sourcepub fn strict_cmp(self, other: &[u8]) -> Ordering
 
pub fn strict_cmp(self, other: &[u8]) -> Ordering
Compare with BCP-47 bytes.
The return value is equivalent to what would happen if you first converted
self to a BCP-47 string and then performed a byte comparison.
This function is case-sensitive and results in a total order, so it is appropriate for
binary search. The only argument producing Ordering::Equal
is self.as_str().as_bytes().
Sourcepub fn normalizing_eq(self, other: &str) -> bool
 
pub fn normalizing_eq(self, other: &str) -> bool
Compare with a potentially unnormalized BCP-47 string.
The return value is equivalent to what would happen if you first parsed the BCP-47 string and then performed a structural comparison.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Language
 
impl<'de> Deserialize<'de> for Language
Source§fn deserialize<D>(
    deserializer: D,
) -> Result<Language, <D as Deserializer<'de>>::Error>where
    D: Deserializer<'de>,
 
fn deserialize<D>(
    deserializer: D,
) -> Result<Language, <D as Deserializer<'de>>::Error>where
    D: Deserializer<'de>,
Source§impl Display for Language
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
 
impl Display for Language
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
Source§impl From<Language> for LanguageIdentifier
§Examples
use icu::locale::{langid, subtags::language, LanguageIdentifier};
assert_eq!(LanguageIdentifier::from(language!("en")), langid!("en"));
 
impl From<Language> for LanguageIdentifier
§Examples
use icu::locale::{langid, subtags::language, LanguageIdentifier};
assert_eq!(LanguageIdentifier::from(language!("en")), langid!("en"));Source§fn from(language: Language) -> LanguageIdentifier
 
fn from(language: Language) -> LanguageIdentifier
Source§impl From<Language> for Locale
§Examples
use icu::locale::Locale;
use icu::locale::{locale, subtags::language};
assert_eq!(Locale::from(language!("en")), locale!("en"));
 
impl From<Language> for Locale
§Examples
use icu::locale::Locale;
use icu::locale::{locale, subtags::language};
assert_eq!(Locale::from(language!("en")), locale!("en"));Source§impl From<Language> for TinyAsciiStr<3>
 
impl From<Language> for TinyAsciiStr<3>
Source§fn from(input: Language) -> TinyAsciiStr<3>
 
fn from(input: Language) -> TinyAsciiStr<3>
Source§impl NicheBytes<3> for Language
 
impl NicheBytes<3> for Language
const NICHE_BIT_PATTERN: [u8; 3] = tinystr::TinyAsciiStr<3>::NICHE_BIT_PATTERN
Source§impl Ord for Language
 
impl Ord for Language
Source§impl PartialOrd for Language
 
impl PartialOrd for Language
Source§impl Serialize for Language
 
impl Serialize for Language
Source§fn serialize<__S>(
    &self,
    __serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
    __S: Serializer,
 
fn serialize<__S>(
    &self,
    __serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
    __S: Serializer,
Source§impl ULE for Language
 
impl ULE for Language
Source§fn validate_bytes(bytes: &[u8]) -> Result<(), UleError>
 
fn validate_bytes(bytes: &[u8]) -> Result<(), UleError>
&[u8]. Read moreSource§unsafe fn slice_from_bytes_unchecked(bytes: &[u8]) -> &[Self]
 
unsafe fn slice_from_bytes_unchecked(bytes: &[u8]) -> &[Self]
&[u8], and return it as &[Self] with the same lifetime, assuming
that this byte slice has previously been run through Self::parse_bytes_to_slice() with
success. Read moreSource§impl Writeable for Language
 
impl Writeable for Language
Source§fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>
 
fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>
write_to_parts, and discards any
Part annotations.Source§fn writeable_length_hint(&self) -> LengthHint
 
fn writeable_length_hint(&self) -> LengthHint
Source§fn write_to_string(&self) -> Cow<'_, str>
 
fn write_to_string(&self) -> Cow<'_, str>
String with the data from this Writeable. Like ToString,
but smaller and faster. Read moreSource§fn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error>where
    S: PartsWrite + ?Sized,
 
fn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error>where
    S: PartsWrite + ?Sized,
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.Source§impl<'a> ZeroMapKV<'a> for Language
 
impl<'a> ZeroMapKV<'a> for Language
impl Copy for Language
impl Eq for Language
impl StructuralPartialEq for Language
Auto Trait Implementations§
impl Freeze for Language
impl RefUnwindSafe for Language
impl Send for Language
impl Sync for Language
impl Unpin for Language
impl UnwindSafe for Language
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more