Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create BoundDataProvider, a DataProvider that always loads for the same key #4883

Closed
wants to merge 1 commit into from

Conversation

sffc
Copy link
Member

@sffc sffc commented May 8, 2024

I have been using this type of abstraction in DateTimeFormatter. I realized that this is a more useful abstraction in practice than DynamicDataProvider. I created a ticket to delete DynamicDataProvider in 2.0. #4881

Includes #4880

@sffc sffc requested a review from Manishearth as a code owner May 8, 2024 19:27
@sffc sffc requested a review from robertbastian May 8, 2024 19:28
@sffc sffc changed the title Create BoundProvider, a DataProvider that always loads for the same key Create BoundDataProvider, a DataProvider that always loads for the same key May 8, 2024
@@ -84,6 +84,15 @@ pub trait DataMarker: 'static {
pub trait KeyedDataMarker: DataMarker {
/// The single [`DataKey`] associated with this marker.
const KEY: DataKey;

/// Binds this [`KeyedDataMarker`] to a provider supporting it.
fn bind<P>(provider: P) -> DataProviderWithKey<Self, P>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this helper function because type inference works better at the call site. Instead of doing

DataProviderWithKey::<MyDataMarkerV1, _>::new(provider)

I can just write

MyDataMarkerV1::bind(provider)

/// Unlike [`DataProvider`], the provider is bound to a specific key ahead of time.
///
/// [`AnyMarker`]: crate::any::AnyMarker
pub trait BoundDataProvider<M>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Manishearth suggests documenting the purpose for the type.

@sffc
Copy link
Member Author

sffc commented May 9, 2024

Without objections I will just merge this as part of #4877

@sffc sffc closed this May 9, 2024
@sffc sffc deleted the bound-provider branch May 9, 2024 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant