icu_locale_core/preferences/extensions/unicode/keywords/
variant.rs

1// This file is part of ICU4X. For terms of use, please see the file
2// called LICENSE at the top level of the ICU4X source tree
3// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5use crate::preferences::extensions::unicode::enum_keyword;
6
7#[non_exhaustive]
#[doc =
r" A Unicode Variant Identifier defines a special variant used for locales."]
#[doc = r""]
#[doc =
r" The valid values are listed in [LDML](https://unicode.org/reports/tr35/#UnicodeVariantIdentifier)."]
pub enum CommonVariantType {

    #[doc = r" POSIX style locale variant"]
    Posix,
}
#[automatically_derived]
impl ::core::fmt::Debug for CommonVariantType {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "Posix")
    }
}
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for CommonVariantType { }
#[automatically_derived]
impl ::core::clone::Clone for CommonVariantType {
    #[inline]
    fn clone(&self) -> CommonVariantType { *self }
}
#[automatically_derived]
impl ::core::cmp::Eq for CommonVariantType {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {}
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for CommonVariantType { }
#[automatically_derived]
impl ::core::cmp::PartialEq for CommonVariantType {
    #[inline]
    fn eq(&self, other: &CommonVariantType) -> bool { true }
}
#[automatically_derived]
impl ::core::marker::Copy for CommonVariantType { }
#[automatically_derived]
impl ::core::hash::Hash for CommonVariantType {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {}
}
impl crate::preferences::PreferenceKey for CommonVariantType {
    fn unicode_extension_key() -> Option<crate::extensions::unicode::Key> {
        Some(const {
                    use crate::extensions::unicode::Key;
                    match Key::try_from_utf8("va".as_bytes()) {
                        Ok(r) => r,
                        _ => {
                            ::core::panicking::panic_fmt(format_args!("Invalid extensions::unicode::Key: va"));
                        }
                    }
                })
    }
    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) {
            Self::try_from(value).map(Some)
        } else { Ok(None) }
    }
    fn unicode_extension_value(&self)
        -> Option<crate::extensions::unicode::Value> {
        Some((*self).into())
    }
}
impl TryFrom<&crate::extensions::unicode::Value> for CommonVariantType {
    type Error =
        crate::preferences::extensions::unicode::errors::PreferencesParseError;
    fn try_from(s: &crate::extensions::unicode::Value)
        -> Result<Self, Self::Error> {
        let subtag =
            s.get_subtag(0).unwrap_or(&const {
                            use crate::subtags::Subtag;
                            match Subtag::try_from_utf8("true".as_bytes()) {
                                Ok(r) => r,
                                _ => {
                                    ::core::panicking::panic_fmt(format_args!("Invalid subtags::Subtag: true"));
                                }
                            }
                        });
        #[allow(unused_imports)]
        use crate::extensions::unicode::value;
        Ok(match subtag.as_str() {
                "posix" => { CommonVariantType::Posix }
                _ => { return Err(Self::Error::InvalidKeywordValue); }
            })
    }
}
impl From<CommonVariantType> for crate::extensions::unicode::Value {
    fn from(input: CommonVariantType) -> crate::extensions::unicode::Value {
        let f;
        #[allow(unused_mut)]
        let mut s = None;
        match input
            {
                #[allow(non_snake_case)]
                CommonVariantType::Posix => {
                f =
                    const {
                            use crate::subtags::Subtag;
                            match Subtag::try_from_utf8("posix".as_bytes()) {
                                Ok(r) => r,
                                _ => {
                                    ::core::panicking::panic_fmt(format_args!("Invalid subtags::Subtag: posix"));
                                }
                            }
                        };
            }
        }
        if let Some(s) = s {
            crate::extensions::unicode::Value::from_two_subtags(f, s)
        } else { crate::extensions::unicode::Value::from_subtag(Some(f)) }
    }
}
impl CommonVariantType {
    /// A helper function for displaying as a `&str`.
    pub const fn as_str(&self) -> &'static str {
        match self
            {
                #[allow(non_snake_case)]
                Self::Posix => {
                return "posix";
            }
        }
    }
}enum_keyword!(
8    /// A Unicode Variant Identifier defines a special variant used for locales.
9    ///
10    /// The valid values are listed in [LDML](https://unicode.org/reports/tr35/#UnicodeVariantIdentifier).
11    CommonVariantType {
12        /// POSIX style locale variant
13        ("posix" => Posix),
14}, "va");