Struct icu_provider::AuxiliaryKeys
source · pub struct AuxiliaryKeys {
value: AuxiliaryKeysInner,
}
Expand description
The “auxiliary key” is an annotation on DataLocale
that can contain an arbitrary
information that does not fit into the LanguageIdentifier
or Keywords
.
A DataLocale
can have multiple auxiliary keys, represented by this struct. The auxiliary
keys are stored as private use subtags following -x-
.
An auxiliary key currently allows 1-8 lowercase alphanumerics.
§Examples
use icu_locid::langid;
use icu_provider::prelude::*;
use writeable::assert_writeable_eq;
let mut data_locale: DataLocale = langid!("ar-EG").into();
assert_writeable_eq!(data_locale, "ar-EG");
assert!(!data_locale.has_aux());
assert_eq!(data_locale.get_aux(), None);
let aux = "gbp"
.parse::<AuxiliaryKeys>()
.expect("contains valid characters");
data_locale.set_aux(aux);
assert_writeable_eq!(data_locale, "ar-EG-x-gbp");
assert!(data_locale.has_aux());
assert_eq!(data_locale.get_aux(), Some(&"gbp".parse().unwrap()));
Multiple auxiliary keys are allowed:
use icu_provider::prelude::*;
use writeable::assert_writeable_eq;
let data_locale = "ar-EG-x-gbp-long".parse::<DataLocale>().unwrap();
assert_writeable_eq!(data_locale, "ar-EG-x-gbp-long");
assert_eq!(data_locale.get_aux().unwrap().iter().count(), 2);
Not all strings are valid auxiliary keys. The string must be well-formed and case-normalized:
use icu_provider::prelude::*;
assert!("abcdefg".parse::<AuxiliaryKeys>().is_ok());
assert!("abc-xyz".parse::<AuxiliaryKeys>().is_ok());
assert!("".parse::<AuxiliaryKeys>().is_err());
assert!("!@#$%".parse::<AuxiliaryKeys>().is_err());
assert!("abc_xyz".parse::<AuxiliaryKeys>().is_err());
assert!("ABC123".parse::<AuxiliaryKeys>().is_err());
Fields§
§value: AuxiliaryKeysInner
Implementations§
source§impl AuxiliaryKeys
impl AuxiliaryKeys
sourcepub fn try_from_iter(
iter: impl IntoIterator<Item = Subtag>,
) -> Result<Self, DataError>
pub fn try_from_iter( iter: impl IntoIterator<Item = Subtag>, ) -> Result<Self, DataError>
Creates an AuxiliaryKeys
from an iterator of individual keys.
§Examples
use icu_locid::extensions::private::subtag;
use icu_provider::prelude::*;
// Single auxiliary key:
let a = AuxiliaryKeys::try_from_iter([subtag!("abc")]).unwrap();
let b = "abc".parse::<AuxiliaryKeys>().unwrap();
assert_eq!(a, b);
// Multiple auxiliary keys:
let a = AuxiliaryKeys::try_from_iter([subtag!("abc"), subtag!("defg")])
.unwrap();
let b = "abc-defg".parse::<AuxiliaryKeys>().unwrap();
assert_eq!(a, b);
The iterator can’t be empty:
use icu_provider::prelude::*;
assert!(AuxiliaryKeys::try_from_iter([]).is_err());
sourcepub const fn from_subtag(input: Subtag) -> Self
pub const fn from_subtag(input: Subtag) -> Self
Creates an AuxiliaryKeys
from a single subtag.
§Examples
use icu_locid::extensions::private::subtag;
use icu_provider::prelude::*;
// Single auxiliary key:
let a = AuxiliaryKeys::from_subtag(subtag!("abc"));
let b = "abc".parse::<AuxiliaryKeys>().unwrap();
assert_eq!(a, b);
sourcepub fn iter(&self) -> impl Iterator<Item = Subtag> + '_
pub fn iter(&self) -> impl Iterator<Item = Subtag> + '_
Iterates over the components of the auxiliary key.
§Example
use icu_locid::extensions::private::subtag;
use icu_provider::AuxiliaryKeys;
let aux: AuxiliaryKeys = "abc-defg".parse().unwrap();
assert_eq!(
aux.iter().collect::<Vec<_>>(),
vec![subtag!("abc"), subtag!("defg")]
);
Trait Implementations§
source§impl Clone for AuxiliaryKeys
impl Clone for AuxiliaryKeys
source§fn clone(&self) -> AuxiliaryKeys
fn clone(&self) -> AuxiliaryKeys
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for AuxiliaryKeys
impl Debug for AuxiliaryKeys
source§impl Display for AuxiliaryKeys
impl Display for AuxiliaryKeys
This trait is implemented for compatibility with fmt!
.
To create a string, Writeable::write_to_string
is usually more efficient.
source§impl From<Subtag> for AuxiliaryKeys
impl From<Subtag> for AuxiliaryKeys
source§impl FromStr for AuxiliaryKeys
impl FromStr for AuxiliaryKeys
source§impl Hash for AuxiliaryKeys
impl Hash for AuxiliaryKeys
source§impl Ord for AuxiliaryKeys
impl Ord for AuxiliaryKeys
source§fn cmp(&self, other: &AuxiliaryKeys) -> Ordering
fn cmp(&self, other: &AuxiliaryKeys) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for AuxiliaryKeys
impl PartialEq for AuxiliaryKeys
source§fn eq(&self, other: &AuxiliaryKeys) -> bool
fn eq(&self, other: &AuxiliaryKeys) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for AuxiliaryKeys
impl PartialOrd for AuxiliaryKeys
source§fn partial_cmp(&self, other: &AuxiliaryKeys) -> Option<Ordering>
fn partial_cmp(&self, other: &AuxiliaryKeys) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Writeable for AuxiliaryKeys
impl Writeable for AuxiliaryKeys
source§fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
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.