diff --git a/Cargo.lock b/Cargo.lock index c011278f528..7f57018224f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1382,6 +1382,7 @@ dependencies = [ name = "icu_provider_macros" version = "0.5.0" dependencies = [ + "icu_provider", "proc-macro2", "quote", "syn", diff --git a/components/calendar/src/japanese.rs b/components/calendar/src/japanese.rs index 89699e6da71..05fd69abdc5 100644 --- a/components/calendar/src/japanese.rs +++ b/components/calendar/src/japanese.rs @@ -27,19 +27,11 @@ pub struct JapaneseDateInner { impl Japanese { /// Creates a new [`Japanese`] from locale data and an options bag. - pub fn try_new + ?Sized>( + pub fn try_new + ?Sized>( data_provider: &D, ) -> Result { let eras = data_provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: provider::key::JAPANESE_ERAS_V1, - options: ResourceOptions { - variant: None, - langid: None, - }, - }, - })? + .load_resource(&DataRequest::default())? .take_payload()?; Ok(Self { eras }) } diff --git a/components/calendar/src/provider.rs b/components/calendar/src/provider.rs index cef2ec95d69..513263ed390 100644 --- a/components/calendar/src/provider.rs +++ b/components/calendar/src/provider.rs @@ -33,7 +33,7 @@ pub struct EraStartDate { pub day: u8, } -#[icu_provider::data_struct] +#[icu_provider::data_struct(JapaneseErasV1Marker = "calendar/japanese@1")] #[derive(Debug, PartialEq, Clone, Default)] #[cfg_attr( feature = "provider_serde", diff --git a/components/datetime/README.md b/components/datetime/README.md index 2c4e8fee35e..143beb8a517 100644 --- a/components/datetime/README.md +++ b/components/datetime/README.md @@ -5,7 +5,7 @@ This API provides necessary functionality for formatting date and time to user readable textual representation. [`DateTimeFormat`] is the main structure of the component. It accepts a set of arguments which -allow it to collect necessary data from the [`DataProvider`], and once instantiated, can be +allow it to collect necessary data from the [data provider], and once instantiated, can be used to quickly format any date and time provided. ## Examples @@ -64,7 +64,7 @@ we expect to add more ways to customize the output, like skeletons, and componen to develop core date and time APIs that will work as an input for this component. [`DateTime`] additionally has support for non-Gregorian calendars, which this module will eventually be able to format. -[`DataProvider`]: icu_provider::DataProvider +[data provider]: icu_provider [`ICU4X`]: ../icu/index.html [`Length`]: options::length [`DateTime`]: icu_calendar::DateTime diff --git a/components/datetime/src/datetime.rs b/components/datetime/src/datetime.rs index a4be0f02e28..0dd2ea5002e 100644 --- a/components/datetime/src/datetime.rs +++ b/components/datetime/src/datetime.rs @@ -13,13 +13,13 @@ use crate::{ use alloc::string::String; use core::marker::PhantomData; use icu_locid::Locale; -use icu_plurals::provider::PluralRulesV1Marker; +use icu_plurals::provider::OrdinalV1Marker; use icu_provider::prelude::*; use crate::{date::DateTimeInput, CldrCalendar, DateTimeFormatError, FormattedDateTime}; /// [`DateTimeFormat`] is the main structure of the [`icu_datetime`] component. -/// When constructed, it uses data from the [`DataProvider`], selected [`Locale`] and provided options to +/// When constructed, it uses data from the [data provider], selected [`Locale`] and provided options to /// collect all data necessary to format any dates into that locale. /// /// For that reason, one should think of the process of formatting a date in two steps - first, a computational @@ -56,12 +56,13 @@ use crate::{date::DateTimeInput, CldrCalendar, DateTimeFormatError, FormattedDat /// let value = dtf.format_to_string(&datetime); /// ``` /// -/// This model replicates that of `ICU` and `ECMA402`. In the future this will become even more pronounced -/// when we introduce asynchronous [`DataProvider`] and corresponding asynchronous constructor. +/// This model replicates that of `ICU` and `ECMA402`. +/// +/// [data provider]: icu_provider pub struct DateTimeFormat(pub(super) raw::DateTimeFormat, PhantomData); impl DateTimeFormat { - /// Constructor that takes a selected [`Locale`], reference to a [`DataProvider`] and + /// Constructor that takes a selected [`Locale`], reference to a [data provider] and /// a list of options, then collects all data necessary to format date and time values into the given locale. /// /// # Examples @@ -83,6 +84,8 @@ impl DateTimeFormat { /// /// assert_eq!(dtf.is_ok(), true); /// ``` + /// + /// [data provider]: icu_provider #[inline] pub fn try_new, D>( locale: T, @@ -90,10 +93,10 @@ impl DateTimeFormat { options: &DateTimeFormatOptions, ) -> Result where - D: DataProvider - + DataProvider - + DataProvider - + DataProvider, + D: ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider, { Ok(Self( raw::DateTimeFormat::try_new(locale, data_provider, options, C::IDENTIFIER)?, diff --git a/components/datetime/src/error.rs b/components/datetime/src/error.rs index 76946e7b5a4..5f62299a7a2 100644 --- a/components/datetime/src/error.rs +++ b/components/datetime/src/error.rs @@ -20,7 +20,7 @@ pub enum DateTimeFormatError { /// An error originating from the [`Write`](std::fmt::Write) trait. #[displaydoc("{0}")] Format(core::fmt::Error), - /// An error originating inside of the [`DataProvider`](icu_provider::DataProvider). + /// An error originating inside of the [data provider](icu_provider). #[displaydoc("{0}")] DataProvider(DataError), /// An error originating from a missing field in datetime input. diff --git a/components/datetime/src/format/datetime.rs b/components/datetime/src/format/datetime.rs index 9c12be54cb2..729af765706 100644 --- a/components/datetime/src/format/datetime.rs +++ b/components/datetime/src/format/datetime.rs @@ -359,14 +359,12 @@ mod tests { let provider = icu_testdata::get_provider(); let data: DataPayload = provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: provider::key::DATE_SYMBOLS_V1, - options: ResourceOptions { - variant: Some("gregory".into()), - langid: Some("en".parse().unwrap()), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + variant: Some("gregory".into()), + langid: Some("en".parse().unwrap()), }, + metadata: Default::default(), }) .unwrap() .take_payload() diff --git a/components/datetime/src/lib.rs b/components/datetime/src/lib.rs index 9d2b6785dc6..395acca9c5e 100644 --- a/components/datetime/src/lib.rs +++ b/components/datetime/src/lib.rs @@ -9,7 +9,7 @@ //! This API provides necessary functionality for formatting date and time to user readable textual representation. //! //! [`DateTimeFormat`] is the main structure of the component. It accepts a set of arguments which -//! allow it to collect necessary data from the [`DataProvider`], and once instantiated, can be +//! allow it to collect necessary data from the [data provider], and once instantiated, can be //! used to quickly format any date and time provided. //! //! # Examples @@ -70,7 +70,7 @@ //! to develop core date and time APIs that will work as an input for this component. [`DateTime`] additionally //! has support for non-Gregorian calendars, which this module will eventually be able to format. //! -//! [`DataProvider`]: icu_provider::DataProvider +//! [data provider]: icu_provider //! [`ICU4X`]: ../icu/index.html //! [`Length`]: options::length //! [`DateTime`]: icu_calendar::DateTime diff --git a/components/datetime/src/provider/calendar/mod.rs b/components/datetime/src/provider/calendar/mod.rs index 94e1590bbfe..9b2de0d7481 100644 --- a/components/datetime/src/provider/calendar/mod.rs +++ b/components/datetime/src/provider/calendar/mod.rs @@ -8,14 +8,12 @@ mod skeletons; mod symbols; use crate::pattern; -use icu_provider::{ - yoke::{self, *}, - DataMarker, -}; +use icu_provider::prelude::*; +use icu_provider::yoke; pub use skeletons::*; pub use symbols::*; -#[icu_provider::data_struct] +#[icu_provider::data_struct(DatePatternsV1Marker = "datetime/lengths@1")] #[derive(Debug, PartialEq, Clone, Default)] #[cfg_attr( feature = "provider_serde", diff --git a/components/datetime/src/provider/calendar/skeletons.rs b/components/datetime/src/provider/calendar/skeletons.rs index 03cd3ab05d6..6edc2070391 100644 --- a/components/datetime/src/provider/calendar/skeletons.rs +++ b/components/datetime/src/provider/calendar/skeletons.rs @@ -9,10 +9,10 @@ use crate::{ skeleton::{reference::Skeleton, SkeletonError}, }; use core::convert::TryFrom; -use icu_provider::yoke::{self, *}; +use icu_provider::yoke; use litemap::LiteMap; -#[icu_provider::data_struct] +#[icu_provider::data_struct(DateSkeletonPatternsV1Marker = "datetime/skeletons@1")] #[derive(Debug, PartialEq, Clone, Default)] #[cfg_attr( feature = "provider_serde", diff --git a/components/datetime/src/provider/calendar/symbols.rs b/components/datetime/src/provider/calendar/symbols.rs index 4e88c5ad6dd..4b686aa5a8c 100644 --- a/components/datetime/src/provider/calendar/symbols.rs +++ b/components/datetime/src/provider/calendar/symbols.rs @@ -8,7 +8,7 @@ use alloc::borrow::Cow; use icu_provider::yoke::{self, *}; use zerovec::map::ZeroMap; -#[icu_provider::data_struct] +#[icu_provider::data_struct(DateSymbolsV1Marker = "datetime/symbols@1")] #[derive(Debug, PartialEq, Clone, Default)] #[cfg_attr( feature = "provider_serde", diff --git a/components/datetime/src/provider/date_time.rs b/components/datetime/src/provider/date_time.rs index cba5085fe5b..196e75e3368 100644 --- a/components/datetime/src/provider/date_time.rs +++ b/components/datetime/src/provider/date_time.rs @@ -81,7 +81,7 @@ impl Clone for PatternSelector<'_, D> { impl PatternSelector<'_, D> where - D: DataProvider + DataProvider, + D: ResourceProvider + ResourceProvider, { pub(crate) fn for_options<'a>( data_provider: &'a D, @@ -208,14 +208,12 @@ where fn patterns_data_payload(self) -> Result> { let data = self .data_provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: provider::key::DATE_PATTERNS_V1, - options: ResourceOptions { - variant: Some(self.calendar.into()), - langid: Some(self.locale.clone().into()), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + variant: Some(self.calendar.into()), + langid: Some(self.locale.clone().into()), }, + metadata: Default::default(), })? .take_payload()?; Ok(data) @@ -224,14 +222,12 @@ where fn skeleton_data_payload(self) -> Result> { let data = self .data_provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: provider::key::DATE_SKELETON_PATTERNS_V1, - options: ResourceOptions { - variant: Some(self.calendar.into()), - langid: Some(self.locale.clone().into()), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + variant: Some(self.calendar.into()), + langid: Some(self.locale.clone().into()), }, + metadata: Default::default(), })? .take_payload()?; Ok(data) diff --git a/components/datetime/src/provider/time_zones.rs b/components/datetime/src/provider/time_zones.rs index ff0ba089e0a..8628aea7383 100644 --- a/components/datetime/src/provider/time_zones.rs +++ b/components/datetime/src/provider/time_zones.rs @@ -3,7 +3,7 @@ // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). use alloc::borrow::Cow; -use icu_provider::yoke::{self, *}; +use icu_provider::yoke; use litemap::LiteMap; use tinystr::TinyStr8; @@ -84,7 +84,7 @@ macro_rules! map_access_with_overrides { /// An ICU4X mapping to the CLDR timeZoneNames format strings. /// See CLDR-JSON timeZoneNames.json for more context. -#[icu_provider::data_struct] +#[icu_provider::data_struct(TimeZoneFormatsV1Marker = "time_zone/formats@1")] #[derive(PartialEq, Debug, Clone, Default)] #[cfg_attr( feature = "provider_serde", @@ -109,7 +109,7 @@ pub struct TimeZoneFormatsV1<'data> { /// An ICU4X mapping to the CLDR timeZoneNames exemplar cities. /// See CLDR-JSON timeZoneNames.json for more context. -#[icu_provider::data_struct] +#[icu_provider::data_struct(ExemplarCitiesV1Marker = "time_zone/exemplar_cities@1")] #[derive(PartialEq, Debug, Clone, Default)] #[cfg_attr( feature = "provider_serde", @@ -121,7 +121,7 @@ map_access!(ExemplarCitiesV1<'data>[str] => Cow<'data, str>: 'data); /// An ICU4X mapping to the long-form generic metazone names. /// See CLDR-JSON timeZoneNames.json for more context. -#[icu_provider::data_struct] +#[icu_provider::data_struct(MetaZoneGenericNamesLongV1Marker = "time_zone/generic_long@1")] #[derive(PartialEq, Debug, Clone, Default)] #[cfg_attr( feature = "provider_serde", @@ -138,7 +138,7 @@ map_access_with_overrides!(MetaZoneGenericNamesLongV1<'data>[str] => Cow<'data, /// An ICU4X mapping to the short-form generic metazone names. /// See CLDR-JSON timeZoneNames.json for more context. -#[icu_provider::data_struct] +#[icu_provider::data_struct(MetaZoneGenericNamesShortV1Marker = "time_zone/generic_short@1")] #[derive(PartialEq, Debug, Clone, Default)] #[cfg_attr( feature = "provider_serde", @@ -156,7 +156,7 @@ map_access_with_overrides!(MetaZoneGenericNamesShortV1<'data>[str] => Cow<'data, /// An ICU4X mapping to the long-form specific metazone names. /// Specific names include time variants such as "daylight." /// See CLDR-JSON timeZoneNames.json for more context. -#[icu_provider::data_struct] +#[icu_provider::data_struct(MetaZoneSpecificNamesLongV1Marker = "time_zone/specific_long@1")] #[derive(PartialEq, Debug, Clone, Default)] #[cfg_attr( feature = "provider_serde", @@ -174,7 +174,7 @@ map_access_with_overrides!(MetaZoneSpecificNamesLongV1<'data>[str] => MetaZoneSp /// An ICU4X mapping to the short-form specific metazone names. /// Specific names include time variants such as "daylight." /// See CLDR-JSON timeZoneNames.json for more context. -#[icu_provider::data_struct] +#[icu_provider::data_struct(MetaZoneSpecificNamesShortV1Marker = "time_zone/specific_short@1")] #[derive(PartialEq, Debug, Clone, Default)] #[cfg_attr( feature = "provider_serde", diff --git a/components/datetime/src/raw/datetime.rs b/components/datetime/src/raw/datetime.rs index 1f391965055..08ea6ebf45b 100644 --- a/components/datetime/src/raw/datetime.rs +++ b/components/datetime/src/raw/datetime.rs @@ -14,7 +14,7 @@ use crate::{ }; use alloc::string::String; use icu_locid::Locale; -use icu_plurals::{provider::PluralRulesV1Marker, PluralRuleType, PluralRules}; +use icu_plurals::{provider::OrdinalV1Marker, PluralRules}; use icu_provider::prelude::*; use crate::{ @@ -44,10 +44,10 @@ impl DateTimeFormat { calendar: &'static str, ) -> Result where - D: DataProvider - + DataProvider - + DataProvider - + DataProvider, + D: ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider, { let locale = locale.into(); @@ -64,11 +64,7 @@ impl DateTimeFormat { let langid: icu_locid::LanguageIdentifier = locale.clone().into(); let ordinal_rules = if let PatternPlurals::MultipleVariants(_) = &patterns.get().0 { - Some(PluralRules::try_new( - locale.clone(), - data_provider, - PluralRuleType::Ordinal, - )?) + Some(PluralRules::try_new_ordinal(locale.clone(), data_provider)?) } else { None }; @@ -76,14 +72,12 @@ impl DateTimeFormat { let symbols_data = if requires_data { Some( data_provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: provider::key::DATE_SYMBOLS_V1, - options: ResourceOptions { - variant: Some(calendar.into()), - langid: Some(langid), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + variant: Some(calendar.into()), + langid: Some(langid), }, + metadata: Default::default(), })? .take_payload()?, ) diff --git a/components/datetime/src/raw/zoned_datetime.rs b/components/datetime/src/raw/zoned_datetime.rs index f4630683775..055038f2976 100644 --- a/components/datetime/src/raw/zoned_datetime.rs +++ b/components/datetime/src/raw/zoned_datetime.rs @@ -4,8 +4,8 @@ use alloc::string::String; use icu_locid::{LanguageIdentifier, Locale}; -use icu_plurals::{provider::PluralRulesV1Marker, PluralRuleType, PluralRules}; -use icu_provider::{DataProvider, DataRequest, ResourceOptions, ResourcePath}; +use icu_plurals::{provider::OrdinalV1Marker, PluralRules}; +use icu_provider::prelude::*; use crate::{ date::ZonedDateTimeInput, @@ -48,17 +48,17 @@ impl ZonedDateTimeFormat { ) -> Result where L: Into, - DP: DataProvider - + DataProvider - + DataProvider, - ZP: DataProvider - + DataProvider - + DataProvider - + DataProvider - + DataProvider - + DataProvider + DP: ResourceProvider + + ResourceProvider + + ResourceProvider, + ZP: ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider + ?Sized, - PP: DataProvider, + PP: ResourceProvider, { let locale = locale.into(); let langid: LanguageIdentifier = locale.clone().into(); @@ -74,10 +74,9 @@ impl ZonedDateTimeFormat { .map_err(|field| DateTimeFormatError::UnsupportedField(field.symbol))?; let ordinal_rules = if let PatternPlurals::MultipleVariants(_) = &patterns.get().0 { - Some(PluralRules::try_new( + Some(PluralRules::try_new_ordinal( locale.clone(), plural_provider, - PluralRuleType::Ordinal, )?) } else { None @@ -86,14 +85,12 @@ impl ZonedDateTimeFormat { let symbols_data = if requires_data { Some( date_provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: provider::key::DATE_SYMBOLS_V1, - options: ResourceOptions { - variant: Some(calendar.into()), - langid: Some(langid), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + variant: Some(calendar.into()), + langid: Some(langid), }, + metadata: Default::default(), })? .take_payload()?, ) diff --git a/components/datetime/src/skeleton/mod.rs b/components/datetime/src/skeleton/mod.rs index 79c562580e8..47725ce6c67 100644 --- a/components/datetime/src/skeleton/mod.rs +++ b/components/datetime/src/skeleton/mod.rs @@ -23,10 +23,7 @@ mod test { use crate::{ fields::{Day, Field, FieldLength, Month, Weekday}, options::components, - provider::{ - calendar::DatePatternsV1Marker, calendar::DateSkeletonPatternsV1Marker, - key::DATE_PATTERNS_V1, key::DATE_SKELETON_PATTERNS_V1, - }, + provider::{calendar::DatePatternsV1Marker, calendar::DateSkeletonPatternsV1Marker}, }; use core::convert::TryFrom; @@ -42,27 +39,23 @@ mod test { let provider = icu_testdata::get_provider(); let langid = langid!("en"); let patterns = provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: DATE_PATTERNS_V1, - options: ResourceOptions { - variant: Some("gregory".into()), - langid: Some(langid.clone()), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + variant: Some("gregory".into()), + langid: Some(langid.clone()), }, + metadata: Default::default(), }) .expect("Failed to load payload") .take_payload() .expect("Failed to retrieve payload"); let skeletons = provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: DATE_SKELETON_PATTERNS_V1, - options: ResourceOptions { - variant: Some("gregory".into()), - langid: Some(langid), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + variant: Some("gregory".into()), + langid: Some(langid), }, + metadata: Default::default(), }) .expect("Failed to load payload") .take_payload() diff --git a/components/datetime/src/time_zone.rs b/components/datetime/src/time_zone.rs index f1f6680bc3b..8bd9b102431 100644 --- a/components/datetime/src/time_zone.rs +++ b/components/datetime/src/time_zone.rs @@ -24,26 +24,23 @@ use icu_provider::prelude::*; /// Loads a resource into its destination if the destination has not already been filled. fn load_resource( locale: &L, - resource_key: ResourceKey, destination: &mut Option>, provider: &P, ) -> Result<(), DateTimeFormatError> where - D: DataMarker, + D: ResourceMarker, L: Clone + Into, - P: DataProvider + ?Sized, + P: ResourceProvider + ?Sized, { if destination.is_none() { *destination = Some( provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: resource_key, - options: ResourceOptions { - variant: None, - langid: Some(locale.clone().into()), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + langid: Some(locale.clone().into()), + variant: None, }, + metadata: Default::default(), })? .take_payload()?, ); @@ -51,7 +48,7 @@ where Ok(()) } -/// [`TimeZoneFormat`] uses data from the [`DataProvider`], the selected [`Locale`], and the provided +/// [`TimeZoneFormat`] uses data from the [data provider], the selected [`Locale`], and the provided /// [`TimeZoneFormatConfig`] to collect all data necessary to format time zones into that locale. /// /// The various time-zone configs specified in UTS-35 require different sets of data for @@ -87,6 +84,8 @@ where /// /// let value = tzf.format_to_string(&time_zone); /// ``` +/// +/// [data provider]: icu_provider pub struct TimeZoneFormat { // The kind of time zone format. pub(super) kind: TimeZoneFormatKind, @@ -118,25 +117,20 @@ impl TimeZoneFormat { ) -> Result where L: Into, - ZP: DataProvider - + DataProvider - + DataProvider - + DataProvider - + DataProvider - + DataProvider + ZP: ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider + ?Sized, { let locale = locale.into(); let zone_formats: DataPayload = zone_provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: provider::key::TIMEZONE_FORMATS_V1, - options: ResourceOptions { - variant: None, - langid: Some(locale.clone().into()), - }, - }, + .load_resource(&DataRequest { + options: locale.clone().into(), + metadata: Default::default(), })? .take_payload()?; @@ -173,18 +167,8 @@ impl TimeZoneFormat { for (length, symbol) in zone_symbols { match symbol { TimeZone::LowerZ => match length { - 1..=3 => load_resource( - &locale, - provider::key::TIMEZONE_SPECIFIC_NAMES_SHORT_V1, - &mut mz_specific_short, - zone_provider, - )?, - 4 => load_resource( - &locale, - provider::key::TIMEZONE_SPECIFIC_NAMES_LONG_V1, - &mut mz_specific_long, - zone_provider, - )?, + 1..=3 => load_resource(&locale, &mut mz_specific_short, zone_provider)?, + 4 => load_resource(&locale, &mut mz_specific_long, zone_provider)?, _ => { return Err(DateTimeFormatError::Pattern( PatternError::FieldLengthInvalid(FieldSymbol::TimeZone(symbol)), @@ -193,32 +177,12 @@ impl TimeZoneFormat { }, TimeZone::LowerV => match length { 1 => { - load_resource( - &locale, - provider::key::TIMEZONE_GENERIC_NAMES_SHORT_V1, - &mut mz_generic_short, - zone_provider, - )?; - load_resource( - &locale, - provider::key::TIMEZONE_EXEMPLAR_CITIES_V1, - &mut exemplar_cities, - zone_provider, - )?; + load_resource(&locale, &mut mz_generic_short, zone_provider)?; + load_resource(&locale, &mut exemplar_cities, zone_provider)?; } 4 => { - load_resource( - &locale, - provider::key::TIMEZONE_GENERIC_NAMES_LONG_V1, - &mut mz_generic_long, - zone_provider, - )?; - load_resource( - &locale, - provider::key::TIMEZONE_EXEMPLAR_CITIES_V1, - &mut exemplar_cities, - zone_provider, - )?; + load_resource(&locale, &mut mz_generic_long, zone_provider)?; + load_resource(&locale, &mut exemplar_cities, zone_provider)?; } _ => { return Err(DateTimeFormatError::Pattern( @@ -229,12 +193,7 @@ impl TimeZoneFormat { TimeZone::UpperV => match length { 1 => (), // BCP-47 identifier, no CLDR-data necessary. 2 => (), // IANA time-zone ID, no CLDR data necessary. - 3 | 4 => load_resource( - &locale, - provider::key::TIMEZONE_EXEMPLAR_CITIES_V1, - &mut exemplar_cities, - zone_provider, - )?, + 3 | 4 => load_resource(&locale, &mut exemplar_cities, zone_provider)?, _ => { return Err(DateTimeFormatError::Pattern( PatternError::FieldLengthInvalid(FieldSymbol::TimeZone(symbol)), @@ -283,25 +242,20 @@ impl TimeZoneFormat { ) -> Result where L: Into, - ZP: DataProvider - + DataProvider - + DataProvider - + DataProvider - + DataProvider - + DataProvider + ZP: ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider + ?Sized, { let locale = locale.into(); let zone_formats: DataPayload = zone_provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: provider::key::TIMEZONE_FORMATS_V1, - options: ResourceOptions { - variant: None, - langid: Some(locale.clone().into()), - }, - }, + .load_resource(&DataRequest { + options: locale.clone().into(), + metadata: Default::default(), })? .take_payload()?; @@ -322,56 +276,21 @@ impl TimeZoneFormat { match config { TimeZoneFormatConfig::GenericNonLocationLong => { - load_resource( - &locale, - provider::key::TIMEZONE_GENERIC_NAMES_LONG_V1, - &mut mz_generic_long, - zone_provider, - )?; - load_resource( - &locale, - provider::key::TIMEZONE_EXEMPLAR_CITIES_V1, - &mut exemplar_cities, - zone_provider, - )?; + load_resource(&locale, &mut mz_generic_long, zone_provider)?; + load_resource(&locale, &mut exemplar_cities, zone_provider)?; } TimeZoneFormatConfig::GenericNonLocationShort => { - load_resource( - &locale, - provider::key::TIMEZONE_GENERIC_NAMES_SHORT_V1, - &mut mz_generic_short, - zone_provider, - )?; - load_resource( - &locale, - provider::key::TIMEZONE_EXEMPLAR_CITIES_V1, - &mut exemplar_cities, - zone_provider, - )?; + load_resource(&locale, &mut mz_generic_short, zone_provider)?; + load_resource(&locale, &mut exemplar_cities, zone_provider)?; } TimeZoneFormatConfig::GenericLocation => { - load_resource( - &locale, - provider::key::TIMEZONE_EXEMPLAR_CITIES_V1, - &mut exemplar_cities, - zone_provider, - )?; + load_resource(&locale, &mut exemplar_cities, zone_provider)?; } TimeZoneFormatConfig::SpecificNonLocationLong => { - load_resource( - &locale, - provider::key::TIMEZONE_SPECIFIC_NAMES_LONG_V1, - &mut mz_specific_long, - zone_provider, - )?; + load_resource(&locale, &mut mz_specific_long, zone_provider)?; } TimeZoneFormatConfig::SpecificNonLocationShort => { - load_resource( - &locale, - provider::key::TIMEZONE_SPECIFIC_NAMES_SHORT_V1, - &mut mz_specific_short, - zone_provider, - )?; + load_resource(&locale, &mut mz_specific_short, zone_provider)?; } TimeZoneFormatConfig::LocalizedGMT | TimeZoneFormatConfig::Iso8601(..) => (), } diff --git a/components/datetime/src/zoned_datetime.rs b/components/datetime/src/zoned_datetime.rs index 234f293ac44..44e198102a7 100644 --- a/components/datetime/src/zoned_datetime.rs +++ b/components/datetime/src/zoned_datetime.rs @@ -5,8 +5,8 @@ use alloc::string::String; use core::marker::PhantomData; use icu_locid::Locale; -use icu_plurals::provider::PluralRulesV1Marker; -use icu_provider::DataProvider; +use icu_plurals::provider::OrdinalV1Marker; +use icu_provider::prelude::*; use crate::{ date::ZonedDateTimeInput, @@ -21,7 +21,7 @@ use crate::{ /// The composition of [`DateTimeFormat`](crate::DateTimeFormat) and [`TimeZoneFormat`](crate::TimeZoneFormat). /// -/// [`ZonedDateTimeFormat`] uses data from the [`DataProvider`]s, the selected [`Locale`], and the +/// [`ZonedDateTimeFormat`] uses data from the [data provider]s, the selected [`Locale`], and the /// provided pattern to collect all data necessary to format a datetime with time zones into that locale. /// /// The various pattern symbols specified in UTS-35 require different sets of data for formatting. @@ -66,8 +66,8 @@ use crate::{ pub struct ZonedDateTimeFormat(raw::ZonedDateTimeFormat, PhantomData); impl ZonedDateTimeFormat { - /// Constructor that takes a selected [`Locale`], a reference to a [`DataProvider`] for - /// dates, a [`DataProvider`] for time zones, and a list of [`DateTimeFormatOptions`]. + /// Constructor that takes a selected [`Locale`], a reference to a [data provider] for + /// dates, a [data provider] for time zones, and a list of [`DateTimeFormatOptions`]. /// It collects all data necessary to format zoned datetime values into the given locale. /// /// # Examples @@ -92,6 +92,8 @@ impl ZonedDateTimeFormat { /// /// assert_eq!(zdtf.is_ok(), true); /// ``` + /// + /// [data provider]: icu_provider #[inline] pub fn try_new( locale: L, @@ -102,17 +104,17 @@ impl ZonedDateTimeFormat { ) -> Result where L: Into, - DP: DataProvider - + DataProvider - + DataProvider, - ZP: DataProvider - + DataProvider - + DataProvider - + DataProvider - + DataProvider - + DataProvider + DP: ResourceProvider + + ResourceProvider + + ResourceProvider, + ZP: ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider + ?Sized, - PP: DataProvider, + PP: ResourceProvider, { Ok(Self( raw::ZonedDateTimeFormat::try_new( diff --git a/components/datetime/tests/datetime.rs b/components/datetime/tests/datetime.rs index 9b57ea85519..ce1d7039806 100644 --- a/components/datetime/tests/datetime.rs +++ b/components/datetime/tests/datetime.rs @@ -19,7 +19,7 @@ use icu_datetime::{ CldrCalendar, DateTimeFormat, DateTimeFormatOptions, ZonedDateTimeFormat, }; use icu_locid::{LanguageIdentifier, Locale}; -use icu_plurals::provider::PluralRulesV1Marker; +use icu_plurals::provider::OrdinalV1Marker; use icu_provider::fork::by_key::MultiForkByKeyProvider; use icu_provider::prelude::*; use icu_provider::struct_provider::AnyPayloadProvider; @@ -98,10 +98,10 @@ fn assert_fixture_element( ) where A: AsCalendar, A::Calendar: CldrCalendar, - D: DataProvider - + DataProvider - + DataProvider - + DataProvider, + D: ResourceProvider + + ResourceProvider + + ResourceProvider + + ResourceProvider, { let locale: Locale = locale.parse().unwrap(); let dtf = DateTimeFormat::::try_new(locale, provider, options).unwrap(); @@ -177,14 +177,12 @@ fn test_dayperiod_patterns() { for test in get_dayperiod_tests("dayperiods").unwrap().0 { let langid: LanguageIdentifier = test.locale.parse().unwrap(); let mut patterns_data: DataPayload = provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: DATE_PATTERNS_V1, - options: ResourceOptions { - variant: Some("gregory".into()), - langid: Some(langid.clone()), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + variant: Some("gregory".into()), + langid: Some(langid.clone()), }, + metadata: Default::default(), }) .unwrap() .take_payload() @@ -193,27 +191,23 @@ fn test_dayperiod_patterns() { data.length_combinations.long = "{0}".parse().unwrap(); }); let symbols_data: DataPayload = provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: DATE_SYMBOLS_V1, - options: ResourceOptions { - variant: Some("gregory".into()), - langid: Some(langid.clone()), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + variant: Some("gregory".into()), + langid: Some(langid.clone()), }, + metadata: Default::default(), }) .unwrap() .take_payload() .unwrap(); let skeleton_data: DataPayload = provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: DATE_SKELETON_PATTERNS_V1, - options: ResourceOptions { - variant: Some("gregory".into()), - langid: Some(langid.clone()), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + variant: Some("gregory".into()), + langid: Some(langid.clone()), }, + metadata: Default::default(), }) .unwrap() .take_payload() @@ -328,40 +322,34 @@ fn test_time_zone_patterns() { datetime.time_zone.time_variant = config.time_variant.take(); let mut patterns_data: DataPayload = date_provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: DATE_PATTERNS_V1, - options: ResourceOptions { - variant: Some("gregory".into()), - langid: Some(langid.clone()), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + variant: Some("gregory".into()), + langid: Some(langid.clone()), }, + metadata: Default::default(), }) .unwrap() .take_payload() .unwrap(); let skeleton_data: DataPayload = date_provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: DATE_SKELETON_PATTERNS_V1, - options: ResourceOptions { - variant: Some("gregory".into()), - langid: Some(langid.clone()), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + variant: Some("gregory".into()), + langid: Some(langid.clone()), }, + metadata: Default::default(), }) .unwrap() .take_payload() .unwrap(); let symbols_data: DataPayload = date_provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: DATE_SYMBOLS_V1, - options: ResourceOptions { - variant: Some("gregory".into()), - langid: Some(langid.clone()), - }, + .load_resource(&DataRequest { + options: ResourceOptions { + variant: Some("gregory".into()), + langid: Some(langid.clone()), }, + metadata: Default::default(), }) .unwrap() .take_payload() diff --git a/components/decimal/src/lib.rs b/components/decimal/src/lib.rs index c43d03d9cca..73b2cdcac61 100644 --- a/components/decimal/src/lib.rs +++ b/components/decimal/src/lib.rs @@ -92,20 +92,18 @@ pub struct FixedDecimalFormat { impl FixedDecimalFormat { /// Creates a new [`FixedDecimalFormat`] from locale data and an options bag. - pub fn try_new, D: DataProvider + ?Sized>( + pub fn try_new< + T: Into, + D: ResourceProvider + ?Sized, + >( locale: T, data_provider: &D, options: options::FixedDecimalFormatOptions, ) -> Result { let symbols = data_provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: provider::key::SYMBOLS_V1, - options: ResourceOptions { - variant: None, - langid: Some(locale.into().into()), - }, - }, + .load_resource(&DataRequest { + options: locale.into().into(), + metadata: Default::default(), })? .take_payload()?; Ok(Self { options, symbols }) diff --git a/components/decimal/src/provider.rs b/components/decimal/src/provider.rs index 64fd1767a0a..451d1849ad7 100644 --- a/components/decimal/src/provider.rs +++ b/components/decimal/src/provider.rs @@ -53,7 +53,7 @@ pub struct GroupingSizesV1 { } /// Symbols and metadata required for formatting a [`FixedDecimal`](crate::FixedDecimal). -#[icu_provider::data_struct] +#[icu_provider::data_struct(DecimalSymbolsV1Marker = "decimal/symbols@1")] #[derive(Debug, PartialEq, Clone)] #[cfg_attr( feature = "provider_serde", diff --git a/components/icu/examples/tui.rs b/components/icu/examples/tui.rs index 68309cebf16..baf776ff164 100644 --- a/components/icu/examples/tui.rs +++ b/components/icu/examples/tui.rs @@ -10,7 +10,7 @@ use icu::calendar::Gregorian; use icu::datetime::DateTimeFormatOptions; use icu::locid::{macros::langid, Locale}; -use icu::plurals::{PluralCategory, PluralRuleType, PluralRules}; +use icu::plurals::{PluralCategory, PluralRules}; use icu_datetime::{mock::zoned_datetime::MockZonedDateTime, ZonedDateTimeFormat}; use icu_uniset::UnicodeSetBuilder; use std::env; @@ -78,8 +78,8 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize { { let en = langid!("en"); - let pr = PluralRules::try_new(en, &provider, PluralRuleType::Cardinal) - .expect("Failed to create PluralRules."); + let pr = + PluralRules::try_new_cardinal(en, &provider).expect("Failed to create PluralRules."); match pr.select(email_count) { PluralCategory::One => print("Note: You have one unread email."), diff --git a/components/locale_canonicalizer/src/locale_canonicalizer.rs b/components/locale_canonicalizer/src/locale_canonicalizer.rs index 43d42c4a985..9520c5728d8 100644 --- a/components/locale_canonicalizer/src/locale_canonicalizer.rs +++ b/components/locale_canonicalizer/src/locale_canonicalizer.rs @@ -225,10 +225,10 @@ macro_rules! maximize_locale { } impl LocaleCanonicalizer { - /// A constructor which takes a [`DataProvider`] and creates a [`LocaleCanonicalizer`]. + /// A constructor which takes a [`ResourceProvider`] and creates a [`LocaleCanonicalizer`]. pub fn new

(provider: &P) -> Result where - P: DataProvider + DataProvider + ?Sized, + P: ResourceProvider + ResourceProvider + ?Sized, { // The `rg` region override and `sd` regional subdivision keys may contain // language codes that require canonicalization. @@ -237,11 +237,11 @@ impl LocaleCanonicalizer { Key::from_tinystr4_unchecked(tinystr4!("sd")), ]; let aliases: DataPayload = provider - .load_payload(&DataRequest::from(key::ALIASES_V1))? + .load_resource(&DataRequest::default())? .take_payload()?; let likely_subtags: DataPayload = provider - .load_payload(&DataRequest::from(key::LIKELY_SUBTAGS_V1))? + .load_resource(&DataRequest::default())? .take_payload()?; Ok(LocaleCanonicalizer { diff --git a/components/locale_canonicalizer/src/provider.rs b/components/locale_canonicalizer/src/provider.rs index 5ed6c02cef4..e3dabb02110 100644 --- a/components/locale_canonicalizer/src/provider.rs +++ b/components/locale_canonicalizer/src/provider.rs @@ -8,7 +8,7 @@ use alloc::vec::Vec; use icu_locid::LanguageIdentifier; -use icu_provider::yoke::{self, *}; +use icu_provider::yoke; use litemap::LiteMap; use tinystr::{TinyStr4, TinyStr8}; @@ -23,7 +23,7 @@ pub mod key { resource_key!("locale_canonicalizer/likelysubtags@1"); } -#[icu_provider::data_struct] +#[icu_provider::data_struct(AliasesV1Marker = "locale_canonicalizer/aliases@1")] #[derive(Debug, PartialEq, Clone, Default)] #[cfg_attr( feature = "provider_serde", @@ -67,7 +67,7 @@ pub struct AliasesV1 { pub subdivision: Vec<(TinyStr8, TinyStr8)>, } -#[icu_provider::data_struct] +#[icu_provider::data_struct(LikelySubtagsV1Marker = "locale_canonicalizer/likelysubtags@1")] #[derive(Debug, PartialEq, Clone, Default)] #[cfg_attr( feature = "provider_serde", diff --git a/components/plurals/benches/parser.rs b/components/plurals/benches/parser.rs index 804eeed92e3..e9c27f6aa2a 100644 --- a/components/plurals/benches/parser.rs +++ b/components/plurals/benches/parser.rs @@ -18,16 +18,11 @@ fn parser(c: &mut Criterion) { let mut rules = vec![]; - for langid in &fixture_data.langs { - let data_payload: DataPayload = provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: icu_plurals::provider::key::CARDINAL_V1, - options: ResourceOptions { - variant: None, - langid: Some(langid.clone()), - }, - }, + for langid in fixture_data.langs { + let data_payload: DataPayload = provider + .load_resource(&DataRequest { + options: langid.into(), + metadata: Default::default(), }) .unwrap() .take_payload() diff --git a/components/plurals/examples/elevator_floors.rs b/components/plurals/examples/elevator_floors.rs index 1571de8956a..177dbc6c58a 100644 --- a/components/plurals/examples/elevator_floors.rs +++ b/components/plurals/examples/elevator_floors.rs @@ -10,7 +10,7 @@ icu_benchmark_macros::static_setup!(); use icu_locid_macros::langid; -use icu_plurals::{PluralCategory, PluralRuleType, PluralRules}; +use icu_plurals::{PluralCategory, PluralRules}; const VALUES: &[usize] = &[0, 2, 25, 1, 3, 2, 4, 10, 7, 0]; @@ -32,7 +32,7 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize { { print("\n====== Elevator Floor (en) example ============", None); - let pr = PluralRules::try_new(lid, &provider, PluralRuleType::Ordinal) + let pr = PluralRules::try_new_ordinal(lid, &provider) .expect("Failed to create a PluralRules instance."); for value in VALUES { diff --git a/components/plurals/examples/unread_emails.rs b/components/plurals/examples/unread_emails.rs index 11d6257d258..f767bab57f7 100644 --- a/components/plurals/examples/unread_emails.rs +++ b/components/plurals/examples/unread_emails.rs @@ -10,7 +10,7 @@ icu_benchmark_macros::static_setup!(); use icu_locid_macros::langid; -use icu_plurals::{PluralCategory, PluralRuleType, PluralRules}; +use icu_plurals::{PluralCategory, PluralRules}; const VALUES: &[usize] = &[0, 2, 25, 1, 3, 2, 4, 10, 7, 0]; @@ -31,7 +31,7 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize { { print("\n====== Unread Emails (en) example ============", None); - let pr = PluralRules::try_new(lid, &provider, PluralRuleType::Cardinal) + let pr = PluralRules::try_new_cardinal(lid, &provider) .expect("Failed to create a PluralRules instance."); for value in VALUES { diff --git a/components/plurals/src/error.rs b/components/plurals/src/error.rs index c9f9196bb78..c390b98784e 100644 --- a/components/plurals/src/error.rs +++ b/components/plurals/src/error.rs @@ -13,7 +13,7 @@ pub enum PluralRulesError { /// A parsing error for the plural rules. #[displaydoc("Parser error: {0}")] Parser(ParserError), - /// An error originating inside of the [`DataProvider`](icu_provider::DataProvider) + /// An error originating from [`icu_provider`]. #[displaydoc("Data provider error: {0}")] DataProvider(DataError), } diff --git a/components/plurals/src/lib.rs b/components/plurals/src/lib.rs index 4edaa4a9a36..2ca74ca12b1 100644 --- a/components/plurals/src/lib.rs +++ b/components/plurals/src/lib.rs @@ -79,6 +79,8 @@ pub use error::PluralRulesError; use icu_locid::Locale; use icu_provider::prelude::*; pub use operands::PluralOperands; +use provider::CardinalV1Marker; +use provider::OrdinalV1Marker; use provider::PluralRulesV1Marker; use rules::runtime::test_rule; @@ -294,31 +296,113 @@ impl PluralRules { /// ``` /// /// [`type`]: PluralRuleType - /// [`data provider`]: icu_provider::DataProvider + /// [`data provider`]: icu_provider pub fn try_new, D>( locale: T, data_provider: &D, rule_type: PluralRuleType, ) -> Result where - D: DataProvider + ?Sized, + D: ResourceProvider + ResourceProvider + ?Sized, + { + match rule_type { + PluralRuleType::Cardinal => Self::try_new_cardinal(locale, data_provider), + PluralRuleType::Ordinal => Self::try_new_ordinal(locale, data_provider), + } + } + + /// Constructs a new `PluralRules` for a given locale for cardinal numbers. + /// + /// Cardinal plural forms express quantities of units such as time, currency or distance, + /// used in conjunction with a number expressed in decimal digits (i.e. "2", not "two"). + /// + /// For example, English has two forms for cardinals: + /// + /// * [`One`]: `1 day` + /// * [`Other`]: `0 days`, `2 days`, `10 days`, `0.3 days` + /// + /// # Examples + /// + /// ``` + /// use icu::locid::macros::langid; + /// use icu::plurals::{PluralRules, PluralCategory}; + /// + /// let lid = langid!("ru"); + /// + /// let dp = icu_testdata::get_provider(); + /// + /// let rules = PluralRules::try_new_cardinal(lid, &dp) + /// .expect("Data should be present"); + /// + /// assert_eq!(rules.select(2_usize), PluralCategory::Few); + /// ``` + /// + /// [`One`]: PluralCategory::One + /// [`Other`]: PluralCategory::Other + pub fn try_new_cardinal, D>( + locale: T, + data_provider: &D, + ) -> Result + where + D: ResourceProvider + ?Sized, + { + let locale = locale.into(); + let rules = data_provider + .load_resource(&DataRequest { + options: locale.clone().into(), + metadata: Default::default(), + })? + .take_payload()? + .cast(); + Self::new(locale, rules) + } + + /// Constructs a new `PluralRules` for a given locale for ordinal numbers. + /// + /// Ordinal plural forms denote the order of items in a set and are always integers. + /// + /// For example, English has four forms for ordinals: + /// + /// * [`One`]: `1st floor`, `21st floor`, `101st floor` + /// * [`Two`]: `2nd floor`, `22nd floor`, `102nd floor` + /// * [`Few`]: `3rd floor`, `23rd floor`, `103rd floor` + /// * [`Other`]: `4th floor`, `11th floor`, `96th floor` + /// + /// # Examples + /// + /// ``` + /// use icu::locid::macros::langid; + /// use icu::plurals::{PluralRules, PluralCategory}; + /// + /// let lid = langid!("ru"); + /// + /// let dp = icu_testdata::get_provider(); + /// + /// let rules = PluralRules::try_new_ordinal(lid, &dp) + /// .expect("Data should be present"); + /// + /// assert_eq!(rules.select(2_usize), PluralCategory::Other); + /// ``` + /// + /// [`One`]: PluralCategory::One + /// [`Two`]: PluralCategory::Two + /// [`Few`]: PluralCategory::Few + /// [`Other`]: PluralCategory::Other + pub fn try_new_ordinal, D>( + locale: T, + data_provider: &D, + ) -> Result + where + D: ResourceProvider + ?Sized, { let locale = locale.into(); - let key = match rule_type { - PluralRuleType::Cardinal => provider::key::CARDINAL_V1, - PluralRuleType::Ordinal => provider::key::ORDINAL_V1, - }; let rules = data_provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key, - options: ResourceOptions { - variant: None, - langid: Some(locale.clone().into()), - }, - }, + .load_resource(&DataRequest { + options: locale.clone().into(), + metadata: Default::default(), })? - .take_payload()?; + .take_payload()? + .cast(); Self::new(locale, rules) } @@ -453,7 +537,7 @@ impl PluralRules { /// Lower-level constructor that allows constructing a [`PluralRules`] directly from /// data obtained from a provider. - pub fn new>( + fn new>( locale: T, rules: DataPayload, ) -> Result { diff --git a/components/plurals/src/provider.rs b/components/plurals/src/provider.rs index dc719455e43..0fac9f5101c 100644 --- a/components/plurals/src/provider.rs +++ b/components/plurals/src/provider.rs @@ -7,7 +7,7 @@ //! Read more about data providers: [`icu_provider`] use crate::rules::runtime::ast::Rule; -use icu_provider::yoke::{self, *}; +use icu_provider::yoke; #[allow(missing_docs)] // TODO(#1029) - Add missing docs. pub mod key { @@ -20,7 +20,11 @@ pub mod key { /// standard plural forms. If none of the rules match, the "other" category is assumed. /// /// More information: -#[icu_provider::data_struct] +#[icu_provider::data_struct( + PluralRulesV1Marker, + CardinalV1Marker = "plurals/cardinal@1", + OrdinalV1Marker = "plurals/ordinal@1" +)] #[derive(Default, Clone, PartialEq, Debug)] #[cfg_attr( feature = "provider_serde", diff --git a/components/plurals/tests/plurals.rs b/components/plurals/tests/plurals.rs index 3474cb0d192..9b65b2c8e27 100644 --- a/components/plurals/tests/plurals.rs +++ b/components/plurals/tests/plurals.rs @@ -4,9 +4,8 @@ use icu_locid_macros::langid; use icu_plurals::{ - provider::{self, PluralRulesV1Marker}, - rules::runtime::ast::Rule, - PluralCategory, PluralRuleType, PluralRules, + provider::CardinalV1Marker, rules::runtime::ast::Rule, PluralCategory, PluralRuleType, + PluralRules, }; use icu_provider::prelude::*; use zerovec::VarZeroVec; @@ -28,15 +27,10 @@ fn test_static_provider_borrowed_rules() { let lid = langid!("en"); - let rules: DataPayload = provider - .load_payload(&DataRequest { - resource_path: ResourcePath { - key: provider::key::CARDINAL_V1, - options: ResourceOptions { - variant: None, - langid: Some(lid), - }, - }, + let rules: DataPayload = provider + .load_resource(&DataRequest { + options: lid.into(), + metadata: Default::default(), }) .expect("Failed to load payload") .take_payload() diff --git a/components/properties/src/maps.rs b/components/properties/src/maps.rs index fe991a26b4d..04d0846ed85 100644 --- a/components/properties/src/maps.rs +++ b/components/properties/src/maps.rs @@ -24,20 +24,11 @@ pub type CodePointMapResult = fn get_cp_map(provider: &D, resc_key: ResourceKey) -> CodePointMapResult where - D: DataProvider> + ?Sized, + D: DynProvider> + ?Sized, T: TrieValue, { - let data_req = DataRequest { - resource_path: ResourcePath { - key: resc_key, - options: ResourceOptions { - variant: None, - langid: None, - }, - }, - }; - - let resp: DataResponse> = provider.load_payload(&data_req)?; + let resp: DataResponse> = + provider.load_payload(resc_key, &Default::default())?; let property_payload: DataPayload> = resp.take_payload()?; Ok(property_payload) @@ -65,7 +56,7 @@ where /// [`CodePointTrie`]: icu_codepointtrie::CodePointTrie pub fn get_general_category(provider: &D) -> CodePointMapResult where - D: DataProvider> + ?Sized, + D: DynProvider> + ?Sized, { get_cp_map(provider, key::GENERAL_CATEGORY_V1) } @@ -92,7 +83,7 @@ where /// [`CodePointTrie`]: icu_codepointtrie::CodePointTrie pub fn get_script(provider: &D) -> CodePointMapResult