pub struct LanguageIdentifier {
    pub language: Language,
    pub script: Option<Script>,
    pub region: Option<Region>,
    pub(crate) variants: Option<Box<[Variant], Global>>,
}
Expand description

LanguageIdentifier is a core struct representing a Unicode Language Identifier.

Examples

use unic_langid_impl::LanguageIdentifier;

let li: LanguageIdentifier = "en-US".parse()
    .expect("Failed to parse.");

assert_eq!(li.language, "en");
assert_eq!(li.script, None);
assert_eq!(li.region.as_ref().map(Into::into), Some("US"));
assert_eq!(li.variants().len(), 0);

Parsing

Unicode recognizes three levels of standard conformance for any language identifier:

  • well-formed - syntactically correct
  • valid - well-formed and only uses registered language subtags, extensions, keywords, types…
  • canonical - valid and no deprecated codes or structure.

At the moment parsing normalizes a well-formed language identifier converting _ separators to - and adjusting casing to conform to the Unicode standard.

Any bogus subtags will cause the parsing to fail with an error. No subtag validation is performed.

Examples:

use unic_langid_impl::LanguageIdentifier;

let li: LanguageIdentifier = "eN_latn_Us-Valencia".parse()
    .expect("Failed to parse.");

assert_eq!(li.language, "en");
assert_eq!(li.script.as_ref().map(Into::into), Some("Latn"));
assert_eq!(li.region.as_ref().map(Into::into), Some("US"));
assert_eq!(li.variants().map(|v| v.as_str()).collect::<Vec<_>>(), &["valencia"]);

Fields

language: Languagescript: Option<Script>region: Option<Region>variants: Option<Box<[Variant], Global>>

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
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.

Layout

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 32 bytes