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(pub(crate) 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_fields_are_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> {
Self::try_from(&input)
}
}
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.as_single_subtag().copied().map(Self).ok_or(PreferencesParseError::InvalidKeywordValue)
})(input)
}
}
impl From<TimeZoneShortId> for crate::extensions::unicode::Value {
fn from(input: TimeZoneShortId) -> crate::extensions::unicode::Value {
(&input).into()
}
}
impl From<&TimeZoneShortId> for crate::extensions::unicode::Value {
fn from(input: &TimeZoneShortId) -> crate::extensions::unicode::Value {
(|input: &TimeZoneShortId|
{ Value::from_subtag(Some(input.0)) })(input)
}
}
impl crate::preferences::PreferenceKey for TimeZoneShortId {
fn unicode_extension_key() -> Option<crate::extensions::unicode::Key> {
Some(Self::UNICODE_EXTENSION_KEY)
}
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 == *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 TimeZoneShortId {
pub(crate) const UNICODE_EXTENSION_KEY: crate::extensions::unicode::Key =
const {
use crate::extensions::unicode::Key;
match Key::try_from_utf8("tz".as_bytes()) {
Ok(r) => r,
_ => {
::core::panicking::panic_fmt(format_args!("Invalid extensions::unicode::Key: tz"));
}
}
};
}
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 .as_single_subtag()
20 .copied()
21 .map(Self)
22 .ok_or(PreferencesParseError::InvalidKeywordValue)
23 },
24 |input: &TimeZoneShortId| {
25 Value::from_subtag(Some(input.0))
26 }
27);