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: Language
§script: Option<Script>
§region: Option<Region>
§variants: Option<Box<[Variant], Global>>
Auto Trait Implementations§
impl RefUnwindSafe for LanguageIdentifier
impl Send for LanguageIdentifier
impl Sync for LanguageIdentifier
impl Unpin for LanguageIdentifier
impl UnwindSafe for LanguageIdentifier
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
Mutably borrows from an owned value. Read more
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