// This file is part of ICU4X. For terms of use, please see the file // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). use crate::extensions::unicode as unicode_ext; use crate::subtags::{Language, Region, Script, Subtag, Variant}; #[cfg(feature = "alloc")] use crate::ParseError; use crate::{LanguageIdentifier, Locale}; use core::cmp::Ordering; use core::default::Default; use core::fmt; use core::hash::Hash; #[cfg(feature = "alloc")] use core::str::FromStr; /// A locale type optimized for use in fallbacking and the ICU4X data pipeline. /// /// [`DataLocale`] contains less functionality than [`Locale`] but more than /// [`LanguageIdentifier`] for better size and performance while still meeting /// the needs of the ICU4X data pipeline. /// /// You can create a [`DataLocale`] from a borrowed [`Locale`], which is more /// efficient than cloning the [`Locale`], but less efficient than converting an owned /// [`Locale`]: /// /// ``` /// use icu_locale_core::locale; /// use icu_provider::DataLocale; /// /// let locale1 = locale!("en-u-ca-buddhist"); /// let data_locale = DataLocale::from(&locale1); /// ``` /// /// [`DataLocale`] only supports `-u-sd` keywords, to reflect the current state of CLDR data /// lookup and fallback. This may change in the future. /// /// ``` /// use icu_locale_core::{locale, Locale}; /// use icu_provider::DataLocale; /// /// let locale = "hi-IN-t-en-h0-hybrid-u-attr-ca-buddhist-sd-inas" /// .parse::() /// .unwrap(); /// /// assert_eq!( /// DataLocale::from(locale), /// DataLocale::from(locale!("hi-IN-u-sd-inas")) /// ); /// ``` #[derive(Clone, Copy, PartialEq, Hash, Eq)] #[non_exhaustive] pub struct DataLocale { /// Language subtag pub language: Language, /// Script subtag pub script: Option