Struct zng_ext_l10n::Lang
source · 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: LanguageIdentifier
Implementations§
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<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for Lang
impl Ord for Lang
source§impl PartialOrd for Lang
impl PartialOrd for Lang
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 Twhere
T: VarValue,
impl<T> AnyVarValue for Twhere
T: VarValue,
source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Access to mut
dyn Any
methods.source§fn clone_boxed(&self) -> Box<dyn AnyVarValue>
fn clone_boxed(&self) -> Box<dyn AnyVarValue>
Clone the value.
source§fn clone_boxed_var(&self) -> Box<dyn AnyVar>
fn clone_boxed_var(&self) -> Box<dyn AnyVar>
Clone the value into a new boxed
LocalVar<Self>
.source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
Gets if
self
equals other
.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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§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
Compare self to
key
and return true
if they are equal.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>
Converts
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>
Converts
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