Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Jun 27, 2024
1 parent 110afd2 commit 403d876
Show file tree
Hide file tree
Showing 163 changed files with 37,510 additions and 2,143 deletions.
4 changes: 4 additions & 0 deletions provider/baked/src/binary_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ impl<K: BinarySearchKey, M: DataMarker> super::DataStore<M> for Data<K, M> {
fn iter(&self) -> Self::IterReturn {
self.0.iter().map(|&(k, _)| K::to_id(k))
}

fn contains(&self, id: DataIdentifierBorrowed) -> bool {
self.0.binary_search_by(|&(k, _)| K::cmp(k, id)).is_ok()
}
}

pub trait BinarySearchKey: 'static {
Expand Down
9 changes: 9 additions & 0 deletions provider/baked/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,15 @@ impl DataExporter for BakedExporter {
})
}
}

impl icu_provider::CanLoad<#marker_bake> for $provider {
fn can_load(
&self,
req: icu_provider::DataRequest,
) -> Result<bool, icu_provider::DataError> {
Ok(icu_provider_baked::DataStore::contains(&Self::#data_ident, req.id))
}
}
},
quote! {
#maybe_msrv
Expand Down
2 changes: 2 additions & 0 deletions provider/baked/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ pub trait DataStore<M: DataMarker> {

type IterReturn: Iterator<Item = DataIdentifierCow<'static>>;
fn iter(&self) -> Self::IterReturn;

fn contains(&self, id: DataIdentifierBorrowed) -> bool;
}
5 changes: 5 additions & 0 deletions provider/baked/tests/data/hello_world_v1_marker.rs.data
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ macro_rules! __impl_hello_world_v1_marker {
Ok(icu_provider::DataResponse { payload: icu_provider::DataPayload::from_static_ref(payload), metadata })
}
}
impl icu_provider::CanLoad<icu_provider::hello_world::HelloWorldV1Marker> for $provider {
fn can_load(&self, req: icu_provider::DataRequest) -> Result<bool, icu_provider::DataError> {
Ok(icu_provider_baked::DataStore::contains(&Self::DATA_HELLO_WORLD_V1_MARKER, req.id))
}
}
};
($ provider : ty , ITER) => {
__impl_hello_world_v1_marker!($provider);
Expand Down
6 changes: 6 additions & 0 deletions provider/core/src/data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ where
}
}

/// TODO
pub trait CanLoad<M: DataMarker>: DataProvider<M> {
/// TODO
fn can_load(&self, req: DataRequest) -> Result<bool, 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.
Expand Down
2 changes: 1 addition & 1 deletion provider/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub mod serde_borrow_de_utils;

mod data_provider;
pub use data_provider::{
BoundDataProvider, DataProvider, DataProviderWithMarker, DynamicDataProvider,
BoundDataProvider, CanLoad, DataProvider, DataProviderWithMarker, DynamicDataProvider,
};
#[cfg(feature = "std")]
pub use data_provider::{IterableDataProvider, IterableDynamicDataProvider};
Expand Down
9 changes: 7 additions & 2 deletions provider/data/calendar/data/week_data_v1_marker.rs.data

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 403d876

Please sign in to comment.