pub struct Lang(pub LanguageIdentifier);Expand description
Identifies the language, region and script of text.
Use the lang! macro to construct one, it does compile-time validation.
Use the unic_langid crate for more advanced operations such as runtime parsing and editing identifiers, this
type is just an alias for the core struct of that crate.
Tuple Fields§
§0: LanguageIdentifierImplementations§
Source§impl Lang
impl Lang
Sourcepub fn direction(&self) -> LayoutDirection
pub fn direction(&self) -> LayoutDirection
Returns character direction of the language.
Sourcepub fn matches(
&self,
other: &Lang,
self_as_range: bool,
other_as_range: bool,
) -> bool
pub fn matches( &self, other: &Lang, self_as_range: bool, other_as_range: bool, ) -> bool
Compares a language to another allowing for either side to use the missing fields as wildcards.
This allows for matching between en (treated as en-*-*-*) and en-US.
§Examples
let l1 = lang!("en");
let l2 = lang!("en-US");
assert_ne!(l1, l2); // "en" != "en-US"
assert!(!l1.matches(&l2, false, false)); // "en" != "en-US"
assert!(l1.matches(&l2, true, false)); // "en-*-*-*" == "en-US"
assert!(!l1.matches(&l2, false, true)); // "en" != "en-*-US-*"
assert!(l1.matches(&l2, true, true)); // "en-*-*-*" == "en-*-US-*"Note that machine variant is ignored when matching.
let pt_br = lang!("pt-BR");
let pt_pt = lang!("pt-PT");
let pt = lang!("pt");
let pt_m = lang!("pt-machine");
assert!(!pt_br.matches(&pt_pt, true, false)); // "pt-BR-*-*" != "pt-PT"
assert!(pt.matches(&pt_pt, true, false)); // "pt-*-*-*" == "pt-PT"
assert!(pt_m.matches(&pt_pt, true, false)); // "pt-machine-*-*" == "pt-PT"
assert!(pt_m.matches(&pt, false, false)); // "pt-machine" == "pt"
assert_ne!(pt_m, pt); // but "pt-machine" != "pt" in `PartialEq`Sourcepub fn is_machine_translation(&self) -> bool
pub fn is_machine_translation(&self) -> bool
If the language has a machine variant.
Machine translated resources are expected to be of lesser quality, but better than nothing.
This variant indicates that the resource should be given lower priority. If a machine generated
resource if reviewed by a human translator the machine variant must be removed.
Sourcepub fn autonym(&self) -> Option<LangAutonym>
pub fn autonym(&self) -> Option<LangAutonym>
Returns the name of the language and region in own language.
The names are in localized title case, when the name is the same in different scripts the script name is part of the language name (currently Hans/Hant).
Returns None if the locale is not one of the 90 most common locales embedded. Language must match,
script must match exactly (omitted different from explicit), region is optional (if not matched returns only language name),
variants are ignored.
Sourcepub fn cmp_display(&self, other: &Lang) -> Ordering
pub fn cmp_display(&self, other: &Lang) -> Ordering
Get ordering of this and other as fmt::Display text.
This method avoids actually allocating a string.
Methods from Deref<Target = LanguageIdentifier>§
pub fn matches<O>(
&self,
other: &O,
self_as_range: bool,
other_as_range: bool,
) -> boolwhere
O: AsRef<LanguageIdentifier>,
pub fn matches<O>(
&self,
other: &O,
self_as_range: bool,
other_as_range: bool,
) -> boolwhere
O: AsRef<LanguageIdentifier>,
Compares a LanguageIdentifier to another AsRef<LanguageIdentifier
allowing for either side to use the missing fields as wildcards.
This allows for matching between en (treated as en-*-*-*) and en-US.
§Examples
use unic_langid_impl::LanguageIdentifier;
let li1: LanguageIdentifier = "en".parse()
.expect("Parsing failed.");
let li2: LanguageIdentifier = "en-US".parse()
.expect("Parsing failed.");
assert_ne!(li1, li2); // "en" != "en-US"
assert_ne!(li1.to_string(), li2.to_string()); // "en" != "en-US"
assert_eq!(li1.matches(&li2, false, false), false); // "en" != "en-US"
assert_eq!(li1.matches(&li2, true, false), true); // "en-*-*-*" == "en-US"
assert_eq!(li1.matches(&li2, false, true), false); // "en" != "en-*-US-*"
assert_eq!(li1.matches(&li2, true, true), true); // "en-*-*-*" == "en-*-US-*"pub fn variants(&self) -> impl ExactSizeIterator
pub fn variants(&self) -> impl ExactSizeIterator
Returns a vector of variants subtags of the LanguageIdentifier.
§Examples
use unic_langid_impl::LanguageIdentifier;
let li1: LanguageIdentifier = "ca-ES-valencia".parse()
.expect("Parsing failed.");
assert_eq!(li1.variants().map(|v| v.as_str()).collect::<Vec<_>>(), &["valencia"]);
let li2: LanguageIdentifier = "de".parse()
.expect("Parsing failed.");
assert_eq!(li2.variants().len(), 0);pub fn has_variant(&self, variant: Variant) -> bool
pub fn has_variant(&self, variant: Variant) -> bool
Tests if a variant subtag is present in the LanguageIdentifier.
§Examples
use unic_langid_impl::LanguageIdentifier;
let mut li: LanguageIdentifier = "ca-ES-macos".parse()
.expect("Parsing failed.");
assert_eq!(li.has_variant("valencia".parse().unwrap()), false);
assert_eq!(li.has_variant("macos".parse().unwrap()), true);pub fn character_direction(&self) -> CharacterDirection
pub fn character_direction(&self) -> CharacterDirection
Returns character direction of the LanguageIdentifier.
§Examples
use unic_langid_impl::{LanguageIdentifier, CharacterDirection};
let li1: LanguageIdentifier = "es-AR".parse()
.expect("Parsing failed.");
let li2: LanguageIdentifier = "fa".parse()
.expect("Parsing failed.");
assert_eq!(li1.character_direction(), CharacterDirection::LTR);
assert_eq!(li2.character_direction(), CharacterDirection::RTL);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Lang
impl<'de> Deserialize<'de> for Lang
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Lang, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Lang, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for Lang
Prints the autonym if built with "lang_autonym" and has one, otherwise prints the tags.
impl Display for Lang
Prints the autonym if built with "lang_autonym" and has one, otherwise prints the tags.
{} prints language and region (if set), {:#} only prints language.
Source§impl Ord for Lang
impl Ord for Lang
Source§impl PartialOrd for Lang
impl PartialOrd for Lang
Source§impl Serialize for Lang
impl Serialize for Lang
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,
impl Eq for Lang
impl IntoValue<Langs> for Lang
impl StructuralPartialEq for Lang
Auto Trait Implementations§
impl Freeze for Lang
impl RefUnwindSafe for Lang
impl Send for Lang
impl Sync for Lang
impl Unpin for Lang
impl UnwindSafe for Lang
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
Source§impl<T> AnyVarValue for T
impl<T> AnyVarValue for T
Source§fn clone_boxed(&self) -> BoxAnyVarValue
fn clone_boxed(&self) -> BoxAnyVarValue
Source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self and other are equal.Source§fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
other if both are of the same type.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,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<T> DataNoteValue for T
impl<T> DataNoteValue for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> FsChangeNote for T
impl<T> FsChangeNote for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<T> Separable for Twhere
T: Display,
impl<T> Separable for Twhere
T: Display,
Source§fn separate_by_policy(&self, policy: SeparatorPolicy<'_>) -> String
fn separate_by_policy(&self, policy: SeparatorPolicy<'_>) -> String
SeparatorPolicy. Read more