Skip to content

Commit

Permalink
Remove AnyProvider (#6086)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored Feb 10, 2025
1 parent 77c4256 commit 957f599
Show file tree
Hide file tree
Showing 103 changed files with 248 additions and 2,400 deletions.
55 changes: 4 additions & 51 deletions components/calendar/src/any_calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,54 +612,8 @@ impl AnyCalendar {
}
}

#[doc = icu_provider::gen_any_buffer_unstable_docs!(ANY, Self::new_for_kind)]
pub fn try_new_for_kind_with_any_provider<P>(
provider: &P,
kind: AnyCalendarKind,
) -> Result<Self, DataError>
where
P: AnyProvider + ?Sized,
{
Ok(match kind {
AnyCalendarKind::Buddhist => AnyCalendar::Buddhist(Buddhist),
AnyCalendarKind::Chinese => {
AnyCalendar::Chinese(Chinese::try_new_with_any_provider(provider)?)
}
AnyCalendarKind::Coptic => AnyCalendar::Coptic(Coptic),
AnyCalendarKind::Dangi => {
AnyCalendar::Dangi(Dangi::try_new_with_any_provider(provider)?)
}
AnyCalendarKind::Ethiopian => AnyCalendar::Ethiopian(Ethiopian::new_with_era_style(
EthiopianEraStyle::AmeteMihret,
)),
AnyCalendarKind::EthiopianAmeteAlem => {
AnyCalendar::Ethiopian(Ethiopian::new_with_era_style(EthiopianEraStyle::AmeteAlem))
}
AnyCalendarKind::Gregorian => AnyCalendar::Gregorian(Gregorian),
AnyCalendarKind::Hebrew => AnyCalendar::Hebrew(Hebrew),
AnyCalendarKind::Indian => AnyCalendar::Indian(Indian),
AnyCalendarKind::IslamicCivil => AnyCalendar::IslamicCivil(IslamicCivil),
AnyCalendarKind::IslamicObservational => AnyCalendar::IslamicObservational(
IslamicObservational::try_new_with_any_provider(provider)?,
),
AnyCalendarKind::IslamicTabular => AnyCalendar::IslamicTabular(IslamicTabular),
AnyCalendarKind::IslamicUmmAlQura => AnyCalendar::IslamicUmmAlQura(
IslamicUmmAlQura::try_new_with_any_provider(provider)?,
),
AnyCalendarKind::Iso => AnyCalendar::Iso(Iso),
AnyCalendarKind::Japanese => {
AnyCalendar::Japanese(Japanese::try_new_with_any_provider(provider)?)
}
AnyCalendarKind::JapaneseExtended => AnyCalendar::JapaneseExtended(
JapaneseExtended::try_new_with_any_provider(provider)?,
),
AnyCalendarKind::Persian => AnyCalendar::Persian(Persian),
AnyCalendarKind::Roc => AnyCalendar::Roc(Roc),
})
}

#[cfg(feature = "serde")]
#[doc = icu_provider::gen_any_buffer_unstable_docs!(BUFFER, Self::new_for_kind)]
#[doc = icu_provider::gen_buffer_unstable_docs!(BUFFER, Self::new_for_kind)]
pub fn try_new_for_kind_with_buffer_provider<P>(
provider: &P,
kind: AnyCalendarKind,
Expand Down Expand Up @@ -705,7 +659,7 @@ impl AnyCalendar {
})
}

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new_for_kind)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new_for_kind)]
pub fn try_new_for_kind_unstable<P>(
provider: &P,
kind: AnyCalendarKind,
Expand Down Expand Up @@ -768,18 +722,17 @@ impl AnyCalendar {
Ok(Self::new_for_kind(kind))
}

icu_provider::gen_any_buffer_data_constructors!(
icu_provider::gen_buffer_data_constructors!(
(prefs: AnyCalendarPreferences) -> error: DataError,
functions: [
try_new: skip,
try_new_with_any_provider,
try_new_with_buffer_provider,
try_new_unstable,
Self,
]
);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::try_new)]
pub fn try_new_unstable<P>(
provider: &P,
prefs: AnyCalendarPreferences,
Expand Down
5 changes: 2 additions & 3 deletions components/calendar/src/chinese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,15 @@ impl Chinese {
}
}

icu_provider::gen_any_buffer_data_constructors!(() -> error: DataError,
icu_provider::gen_buffer_data_constructors!(() -> error: DataError,
functions: [
new: skip,
try_new_with_any_provider,
try_new_with_buffer_provider,
try_new_unstable,
Self,
]);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<D: DataProvider<ChineseCacheV1> + ?Sized>(
provider: &D,
) -> Result<Self, DataError> {
Expand Down
5 changes: 2 additions & 3 deletions components/calendar/src/dangi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,15 @@ impl Dangi {
}
}

icu_provider::gen_any_buffer_data_constructors!(() -> error: DataError,
icu_provider::gen_buffer_data_constructors!(() -> error: DataError,
functions: [
new: skip,
try_new_with_any_provider,
try_new_with_buffer_provider,
try_new_unstable,
Self,
]);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<D: DataProvider<DangiCacheV1> + ?Sized>(
provider: &D,
) -> Result<Self, DataError> {
Expand Down
12 changes: 5 additions & 7 deletions components/calendar/src/islamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,15 @@ impl IslamicObservational {
}
}

icu_provider::gen_any_buffer_data_constructors!(() -> error: DataError,
icu_provider::gen_buffer_data_constructors!(() -> error: DataError,
functions: [
new: skip,
try_new_with_any_provider,
try_new_with_buffer_provider,
try_new_unstable,
Self,
]);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<D: DataProvider<IslamicObservationalCacheV1> + ?Sized>(
provider: &D,
) -> Result<Self, DataError> {
Expand Down Expand Up @@ -167,16 +166,15 @@ impl IslamicUmmAlQura {
}
}

icu_provider::gen_any_buffer_data_constructors!(() -> error: DataError,
icu_provider::gen_buffer_data_constructors!(() -> error: DataError,
functions: [
new: skip,
try_new_with_any_provider,
try_new_with_buffer_provider,
try_new_with_buffer_provider,
try_new_unstable,
Self,
]);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<D: DataProvider<IslamicUmmAlQuraCacheV1> + ?Sized>(
provider: &D,
) -> Result<Self, DataError> {
Expand Down
14 changes: 6 additions & 8 deletions components/calendar/src/japanese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,15 @@ impl Japanese {
}
}

icu_provider::gen_any_buffer_data_constructors!(() -> error: DataError,
icu_provider::gen_buffer_data_constructors!(() -> error: DataError,
functions: [
new: skip,
try_new_with_any_provider,
try_new_with_buffer_provider,
try_new_with_buffer_provider,
try_new_unstable,
Self,
]);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<D: DataProvider<JapaneseErasV1> + ?Sized>(
provider: &D,
) -> Result<Self, DataError> {
Expand Down Expand Up @@ -166,16 +165,15 @@ impl JapaneseExtended {
})
}

icu_provider::gen_any_buffer_data_constructors!(() -> error: DataError,
icu_provider::gen_buffer_data_constructors!(() -> error: DataError,
functions: [
new: skip,
try_new_with_any_provider,
try_new_with_buffer_provider,
try_new_with_buffer_provider,
try_new_unstable,
Self,
]);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<D: DataProvider<JapaneseExtendedErasV1> + ?Sized>(
provider: &D,
) -> Result<Self, DataError> {
Expand Down
4 changes: 2 additions & 2 deletions components/calendar/src/week_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ pub struct WeekCalculator {
}

impl WeekCalculator {
icu_provider::gen_any_buffer_data_constructors!(
icu_provider::gen_buffer_data_constructors!(
(prefs: WeekPreferences) -> error: DataError,
/// Creates a new [`WeekCalculator`] from compiled data.
);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::try_new)]
pub fn try_new_unstable<P>(provider: &P, prefs: WeekPreferences) -> Result<Self, DataError>
where
P: DataProvider<crate::provider::WeekDataV2> + ?Sized,
Expand Down
5 changes: 2 additions & 3 deletions components/casemap/src/casemapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,16 +623,15 @@ impl CaseMapper {
}
}

icu_provider::gen_any_buffer_data_constructors!(() -> error: DataError,
icu_provider::gen_buffer_data_constructors!(() -> error: DataError,
functions: [
new: skip,
try_new_with_any_provider,
try_new_with_buffer_provider,
try_new_unstable,
Self,
]);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<P>(provider: &P) -> Result<CaseMapper, DataError>
where
P: DataProvider<CaseMapV1> + ?Sized,
Expand Down
10 changes: 4 additions & 6 deletions components/casemap/src/closer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ pub struct CaseMapCloser<CM> {
}

impl CaseMapCloser<CaseMapper> {
icu_provider::gen_any_buffer_data_constructors!(() -> error: DataError,
icu_provider::gen_buffer_data_constructors!(() -> error: DataError,
functions: [
new: skip,
try_new_with_any_provider,
try_new_with_buffer_provider,
try_new_unstable,
Self,
]);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>
where
P: DataProvider<CaseMapV1> + DataProvider<CaseMapUnfoldV1> + ?Sized,
Expand Down Expand Up @@ -102,10 +101,9 @@ impl CaseMapCloser<CaseMapper> {

// We use Borrow, not AsRef, since we want the blanket impl on T
impl<CM: AsRef<CaseMapper>> CaseMapCloser<CM> {
icu_provider::gen_any_buffer_data_constructors!((casemapper: CM) -> error: DataError,
icu_provider::gen_buffer_data_constructors!((casemapper: CM) -> error: DataError,
functions: [
new_with_mapper: skip,
try_new_with_mapper_with_any_provider,
try_new_with_mapper_with_buffer_provider,
try_new_with_mapper_unstable,
Self,
Expand All @@ -128,7 +126,7 @@ impl<CM: AsRef<CaseMapper>> CaseMapCloser<CM> {
}

/// Construct this object to wrap an existing CaseMapper (or a reference to one), loading additional data as needed.
#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new_with_mapper)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new_with_mapper)]
pub fn try_new_with_mapper_unstable<P>(provider: &P, casemapper: CM) -> Result<Self, DataError>
where
P: DataProvider<CaseMapV1> + DataProvider<CaseMapUnfoldV1> + ?Sized,
Expand Down
12 changes: 5 additions & 7 deletions components/casemap/src/titlecase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,15 @@ pub struct TitlecaseMapper<CM> {
}

impl TitlecaseMapper<CaseMapper> {
icu_provider::gen_any_buffer_data_constructors!(() -> error: DataError,
icu_provider::gen_buffer_data_constructors!(() -> error: DataError,
functions: [
new: skip,
try_new_with_any_provider,
try_new_with_buffer_provider,
try_new_with_buffer_provider,
try_new_unstable,
Self,
]);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
pub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>
where
P: DataProvider<CaseMapV1> + DataProvider<GeneralCategoryV1> + ?Sized,
Expand All @@ -246,10 +245,9 @@ impl TitlecaseMapper<CaseMapper> {
}
// We use Borrow, not AsRef, since we want the blanket impl on T
impl<CM: AsRef<CaseMapper>> TitlecaseMapper<CM> {
icu_provider::gen_any_buffer_data_constructors!((casemapper: CM) -> error: DataError,
icu_provider::gen_buffer_data_constructors!((casemapper: CM) -> error: DataError,
functions: [
new_with_mapper: skip,
try_new_with_mapper_with_any_provider,
try_new_with_mapper_with_buffer_provider,
try_new_with_mapper_unstable,
Self,
Expand All @@ -271,7 +269,7 @@ impl<CM: AsRef<CaseMapper>> TitlecaseMapper<CM> {
}

/// Construct this object to wrap an existing CaseMapper (or a reference to one), loading additional data as needed.
#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new_with_mapper)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new_with_mapper)]
pub fn try_new_with_mapper_unstable<P>(provider: &P, casemapper: CM) -> Result<Self, DataError>
where
P: DataProvider<CaseMapV1> + DataProvider<GeneralCategoryV1> + ?Sized,
Expand Down
7 changes: 3 additions & 4 deletions components/collator/src/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,17 @@ impl Collator {
CollatorBorrowed::try_new(prefs, options)
}

icu_provider::gen_any_buffer_data_constructors!(
icu_provider::gen_buffer_data_constructors!(
(prefs: CollatorPreferences, options: CollatorOptions) -> error: DataError,
functions: [
try_new: skip,
try_new_with_any_provider,
try_new_with_buffer_provider,
try_new_with_buffer_provider,
try_new_unstable,
Self
]
);

#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new)]
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::try_new)]
pub fn try_new_unstable<D>(
provider: &D,
prefs: CollatorPreferences,
Expand Down
27 changes: 0 additions & 27 deletions components/datetime/src/external_loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,6 @@ impl AnyCalendarLoader for ExternalLoaderCompiledData {
}
}

/// Loader for types from other crates using [`AnyProvider`].
pub(crate) struct ExternalLoaderAny<'a, P: ?Sized>(pub &'a P);

impl<P> DecimalFormatterLoader for ExternalLoaderAny<'_, P>
where
P: ?Sized + AnyProvider,
{
#[inline]
fn load(
&self,
prefs: DecimalFormatterPreferences,
options: DecimalFormatterOptions,
) -> Result<DecimalFormatter, DataError> {
DecimalFormatter::try_new_with_any_provider(self.0, prefs, options)
}
}

impl<P> AnyCalendarLoader for ExternalLoaderAny<'_, P>
where
P: ?Sized + AnyProvider,
{
#[inline]
fn load(&self, prefs: AnyCalendarPreferences) -> Result<AnyCalendar, DataError> {
AnyCalendar::try_new_with_any_provider(self.0, prefs)
}
}

/// Loader for types from other crates using [`BufferProvider`].
#[cfg(feature = "serde")]
pub(crate) struct ExternalLoaderBuffer<'a, P: ?Sized>(pub &'a P);
Expand Down
Loading

0 comments on commit 957f599

Please sign in to comment.