From 24082af3dafa9a47390e9157ea3a34ac42e3118f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Espina=20Del=20=C3=81ngel?= Date: Sat, 28 Dec 2024 12:22:40 -0600 Subject: [PATCH] Add missing `DynamicDryProvider` implementations --- provider/core/src/data_provider.rs | 158 ++++++++++++++++++++++++----- 1 file changed, 132 insertions(+), 26 deletions(-) diff --git a/provider/core/src/data_provider.rs b/provider/core/src/data_provider.rs index 2f5a4cd75cb..9e265820b5e 100644 --- a/provider/core/src/data_provider.rs +++ b/provider/core/src/data_provider.rs @@ -53,15 +53,6 @@ where } } -/// A [`DataProvider`] that can iterate over all supported [`DataIdentifierCow`]s. -/// -/// The provider is not allowed to return `Ok` for requests that were not returned by `iter_ids`, -/// and must not fail with a [`DataErrorKind::IdentifierNotFound`] for requests that were returned. -pub trait IterableDataProvider: DataProvider { - /// Returns a set of [`DataIdentifierCow`]. - fn iter_ids(&self) -> Result, DataError>; -} - #[cfg(target_has_atomic = "ptr")] impl DataProvider for alloc::sync::Arc

where @@ -87,6 +78,60 @@ pub trait DryDataProvider: DataProvider { fn dry_load(&self, req: DataRequest) -> Result; } +impl DryDataProvider for &P +where + M: DataMarker, + P: DryDataProvider + ?Sized, +{ + #[inline] + fn dry_load(&self, req: DataRequest) -> Result { + (*self).dry_load(req) + } +} + +impl DryDataProvider for Box

+where + M: DataMarker, + P: DryDataProvider + ?Sized, +{ + #[inline] + fn dry_load(&self, req: DataRequest) -> Result { + (**self).dry_load(req) + } +} + +impl DryDataProvider for alloc::rc::Rc

+where + M: DataMarker, + P: DryDataProvider + ?Sized, +{ + #[inline] + fn dry_load(&self, req: DataRequest) -> Result { + (**self).dry_load(req) + } +} + +#[cfg(target_has_atomic = "ptr")] +impl DryDataProvider for alloc::sync::Arc

+where + M: DataMarker, + P: DryDataProvider + ?Sized, +{ + #[inline] + fn dry_load(&self, req: DataRequest) -> Result { + (**self).dry_load(req) + } +} + +/// A [`DataProvider`] that can iterate over all supported [`DataIdentifierCow`]s. +/// +/// The provider is not allowed to return `Ok` for requests that were not returned by `iter_ids`, +/// and must not fail with a [`DataErrorKind::IdentifierNotFound`] for requests that were returned. +pub trait IterableDataProvider: DataProvider { + /// Returns a set of [`DataIdentifierCow`]. + fn iter_ids(&self) -> Result, DataError>; +} + /// A data provider that loads data for a specific data type. /// /// Unlike [`DataProvider`], there may be multiple markers corresponding to the same data type. @@ -108,23 +153,6 @@ where ) -> Result, DataError>; } -/// A dynanmic data provider that can determine whether it can load a particular data identifier, -/// potentially cheaper than actually performing the load. -pub trait DynamicDryDataProvider: DynamicDataProvider { - /// This method goes through the motions of [`load_data`], but only returns the metadata. - /// - /// If `dry_load_data` returns an error, [`load_data`] must return the same error, but - /// not vice-versa. Concretely, [`load_data`] could return deserialization or I/O errors - /// that `dry_load_data` cannot predict. - /// - /// [`load_data`]: DynamicDataProvider::load_data - fn dry_load_data( - &self, - marker: DataMarkerInfo, - req: DataRequest, - ) -> Result; -} - impl DynamicDataProvider for &P where M: DynamicDataMarker, @@ -186,6 +214,84 @@ where } } +/// A dynanmic data provider that can determine whether it can load a particular data identifier, +/// potentially cheaper than actually performing the load. +pub trait DynamicDryDataProvider: DynamicDataProvider { + /// This method goes through the motions of [`load_data`], but only returns the metadata. + /// + /// If `dry_load_data` returns an error, [`load_data`] must return the same error, but + /// not vice-versa. Concretely, [`load_data`] could return deserialization or I/O errors + /// that `dry_load_data` cannot predict. + /// + /// [`load_data`]: DynamicDataProvider::load_data + fn dry_load_data( + &self, + marker: DataMarkerInfo, + req: DataRequest, + ) -> Result; +} + +impl DynamicDryDataProvider for &P +where + M: DynamicDataMarker, + P: DynamicDryDataProvider + ?Sized, +{ + #[inline] + fn dry_load_data( + &self, + marker: DataMarkerInfo, + req: DataRequest, + ) -> Result { + (*self).dry_load_data(marker, req) + } +} + +impl DynamicDryDataProvider for Box

+where + M: DynamicDataMarker, + P: DynamicDryDataProvider + ?Sized, +{ + #[inline] + fn dry_load_data( + &self, + marker: DataMarkerInfo, + req: DataRequest, + ) -> Result { + (**self).dry_load_data(marker, req) + } +} + +impl DynamicDryDataProvider for alloc::rc::Rc

+where + M: DynamicDataMarker, + P: DynamicDryDataProvider + ?Sized, +{ + #[inline] + fn dry_load_data( + &self, + marker: DataMarkerInfo, + req: DataRequest, + ) -> Result { + (**self).dry_load_data(marker, req) + } +} + +#[cfg(target_has_atomic = "ptr")] +impl DynamicDryDataProvider for alloc::sync::Arc

+where + M: DynamicDataMarker, + P: DynamicDryDataProvider + ?Sized, +{ + #[inline] + fn dry_load_data( + &self, + marker: DataMarkerInfo, + req: DataRequest, + ) -> Result { + (**self).dry_load_data(marker, req) + } +} + /// A [`DynamicDataProvider`] that can iterate over all supported [`DataIdentifierCow`]s for a certain marker. /// /// The provider is not allowed to return `Ok` for requests that were not returned by `iter_ids`,