icu_locale_core/preferences/extensions/unicode/keywords/
timezone.rs1use crate::preferences::extensions::unicode::errors::PreferencesParseError;
6use crate::preferences::extensions::unicode::struct_keyword;
7use crate::{extensions::unicode::Value, subtags::Subtag};
8
9#[doc = r" A Unicode Timezone Identifier defines a timezone."]
#[doc = r""]
#[doc =
r" The valid values are listed in [LDML](https://unicode.org/reports/tr35/#UnicodeTimezoneIdentifier)."]
#[allow(clippy :: exhaustive_structs)]
pub struct TimeZoneShortId(Subtag);
#[automatically_derived]
#[allow(clippy :: exhaustive_structs)]
impl ::core::marker::Copy for TimeZoneShortId { }
#[automatically_derived]
#[allow(clippy :: exhaustive_structs)]
impl ::core::fmt::Debug for TimeZoneShortId {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"TimeZoneShortId", &&self.0)
}
}
#[automatically_derived]
#[allow(clippy :: exhaustive_structs)]
impl ::core::clone::Clone for TimeZoneShortId {
#[inline]
fn clone(&self) -> TimeZoneShortId {
TimeZoneShortId(::core::clone::Clone::clone(&self.0))
}
}
#[automatically_derived]
#[allow(clippy :: exhaustive_structs)]
impl ::core::cmp::Eq for TimeZoneShortId {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<Subtag>;
}
}
#[automatically_derived]
#[allow(clippy :: exhaustive_structs)]
impl ::core::marker::StructuralPartialEq for TimeZoneShortId { }
#[automatically_derived]
#[allow(clippy :: exhaustive_structs)]
impl ::core::cmp::PartialEq for TimeZoneShortId {
#[inline]
fn eq(&self, other: &TimeZoneShortId) -> bool { self.0 == other.0 }
}
#[automatically_derived]
#[allow(clippy :: exhaustive_structs)]
impl ::core::hash::Hash for TimeZoneShortId {
#[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 TimeZoneShortId {
type Error =
crate::preferences::extensions::unicode::errors::PreferencesParseError;
fn try_from(input: crate::extensions::unicode::Value)
-> Result<Self, Self::Error> {
(|input: Value|
{
input.into_single_subtag().map(Self).ok_or(PreferencesParseError::InvalidKeywordValue)
})(input)
}
}
impl From<TimeZoneShortId> for crate::extensions::unicode::Value {
fn from(input: TimeZoneShortId) -> crate::extensions::unicode::Value {
(|input: TimeZoneShortId|
{
crate::extensions::unicode::Value::from_subtag(Some(input.0))
})(input)
}
}
impl crate::preferences::PreferenceKey for TimeZoneShortId {
fn unicode_extension_key() -> Option<crate::extensions::unicode::Key> {
Some(const {
use crate::extensions::unicode::Key;
match Key::try_from_utf8("tz".as_bytes()) {
Ok(r) =>
r,
#[allow(clippy :: panic)]
_ => {
::core::panicking::panic_fmt(format_args!("Invalid extensions::unicode::Key: tz"));
}
}
})
}
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 TimeZoneShortId {
type Target = Subtag;
fn deref(&self) -> &Self::Target { &self.0 }
}struct_keyword!(
10 [Copy]
14 TimeZoneShortId,
15 "tz",
16 Subtag,
17 |input: Value| {
18 input
19 .into_single_subtag()
20 .map(Self)
21 .ok_or(PreferencesParseError::InvalidKeywordValue)
22 },
23 |input: TimeZoneShortId| {
24 crate::extensions::unicode::Value::from_subtag(Some(input.0))
25 }
26);