icu_locale_core/preferences/extensions/unicode/keywords/
currency.rs1use crate::preferences::extensions::unicode::errors::PreferencesParseError;
6use crate::preferences::extensions::unicode::struct_keyword;
7use crate::{extensions::unicode::Value, subtags::Subtag};
8use tinystr::TinyAsciiStr;
9
10#[doc = r" A Unicode Currency Identifier defines a type of currency."]
#[doc = r""]
#[doc =
r" The valid values are listed in [LDML](https://unicode.org/reports/tr35/#UnicodeCurrencyIdentifier)."]
#[allow(clippy :: exhaustive_structs)]
pub struct CurrencyType(TinyAsciiStr<3>);
#[automatically_derived]
#[allow(clippy :: exhaustive_structs)]
impl ::core::fmt::Debug for CurrencyType {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "CurrencyType",
&&self.0)
}
}
#[automatically_derived]
#[allow(clippy :: exhaustive_structs)]
impl ::core::clone::Clone for CurrencyType {
#[inline]
fn clone(&self) -> CurrencyType {
CurrencyType(::core::clone::Clone::clone(&self.0))
}
}
#[automatically_derived]
#[allow(clippy :: exhaustive_structs)]
impl ::core::cmp::Eq for CurrencyType {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<TinyAsciiStr<3>>;
}
}
#[automatically_derived]
#[allow(clippy :: exhaustive_structs)]
impl ::core::marker::StructuralPartialEq for CurrencyType { }
#[automatically_derived]
#[allow(clippy :: exhaustive_structs)]
impl ::core::cmp::PartialEq for CurrencyType {
#[inline]
fn eq(&self, other: &CurrencyType) -> bool { self.0 == other.0 }
}
#[automatically_derived]
#[allow(clippy :: exhaustive_structs)]
impl ::core::hash::Hash for CurrencyType {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
::core::hash::Hash::hash(&self.0, state)
}
}
impl TryFrom<crate::extensions::unicode::Value> for CurrencyType {
type Error =
crate::preferences::extensions::unicode::errors::PreferencesParseError;
fn try_from(input: crate::extensions::unicode::Value)
-> Result<Self, Self::Error> {
(|input: Value|
{
if let Some(subtag) = input.into_single_subtag() {
let ts = subtag.as_tinystr();
if ts.len() == 3 && ts.is_ascii_alphabetic() {
return Ok(Self(ts.resize()));
}
}
Err(PreferencesParseError::InvalidKeywordValue)
})(input)
}
}
impl From<CurrencyType> for crate::extensions::unicode::Value {
fn from(input: CurrencyType) -> crate::extensions::unicode::Value {
(|input: CurrencyType|
{
crate::extensions::unicode::Value::from_subtag(Some(Subtag::from_tinystr_unvalidated(input.0.resize())))
})(input)
}
}
impl crate::preferences::PreferenceKey for CurrencyType {
fn unicode_extension_key() -> Option<crate::extensions::unicode::Key> {
Some(const {
use crate::extensions::unicode::Key;
match Key::try_from_utf8("cu".as_bytes()) {
Ok(r) =>
r,
#[allow(clippy :: panic)]
_ => {
::core::panicking::panic_fmt(format_args!("Invalid extensions::unicode::Key: cu"));
}
}
})
}
fn try_from_key_value(key: &crate::extensions::unicode::Key,
value: &crate::extensions::unicode::Value)
->
Result<Option<Self>,
crate::preferences::extensions::unicode::errors::PreferencesParseError> {
if Self::unicode_extension_key() == Some(*key) {
let result = Self::try_from(value.clone())?;
Ok(Some(result))
} else { Ok(None) }
}
fn unicode_extension_value(&self)
-> Option<crate::extensions::unicode::Value> {
Some(self.clone().into())
}
}
impl core::ops::Deref for CurrencyType {
type Target = TinyAsciiStr<3>;
fn deref(&self) -> &Self::Target { &self.0 }
}struct_keyword!(
11 CurrencyType,
15 "cu",
16 TinyAsciiStr<3>,
17 |input: Value| {
18 if let Some(subtag) = input.into_single_subtag() {
19 let ts = subtag.as_tinystr();
20 if ts.len() == 3 && ts.is_ascii_alphabetic() {
21 return Ok(Self(ts.resize()));
22 }
23 }
24 Err(PreferencesParseError::InvalidKeywordValue)
25 },
26 |input: CurrencyType| {
27 crate::extensions::unicode::Value::from_subtag(Some(
28 Subtag::from_tinystr_unvalidated(input.0.resize()),
29 ))
30 }
31);