-
Notifications
You must be signed in to change notification settings - Fork 174
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
Make InvariantDataProvider support AnyProvider #1494
Comments
Bit wary about the dependency, but this is a good idea. We can also use this as further impetus to zero-copy all of our types (note that non-zc types cannot ConstDefault) |
I think @iainireland had some concerns about CrabBake and stuff requiring all of our types to be zerocopy, which inhibits experimentation. I guess to solve that here we need to make it so that ConstDefaultProvider also only supports zero-copy structs? |
Yeah, trait bounds take care of the experimentation use case. If you try to construct a ConstDefaultProvider with a data struct that doesn't implement the trait, your code won't compile. |
My concern is about the learning curve of having a variety of different requirements, so overlapping requirements between this and crabbake are a good thing. It looks like we want zero-copy for many reasons, so I think we're priced in for that (and we're getting good value for the effort). Are there any other likely obstacles to making all our objects const-constructible, beyond zero-copy? |
Another slight concern is feature explosion. I think we need to merge up features and be careful about what we add. Or perhaps merge up the feature groups that we test. |
Instead of using ConstDefault and adding that dependency, I think we should just introduce a trait in the data provider core crate like trait UndData {
const UND_DATA: Self;
} And then we can rename "InvariantDataProvider" / "ConstDefaultProvider" to "UndProvider". That trait should be implemented on data structs. If it is not implemented, then you won't be able to make a "UndProvider" for that particular data struct. It is likely that Default impls will mostly look like this, which is fine: impl Default for FooV1 {
fn default() -> Self {
Self::UND_DATA.clone() // or zero-copy clone
}
} |
This works for me and I think that's nicer: we will have a particular notion of "default" and it's not necessary that the "default" for a type used in, say, DecimalSymbolsV1 is the same as one in DateTimeSymbolsV1 |
Conclusion: Don't build a data provider around Default impls. Data structs can implement Default on a case-by-case basis and use AnyPayloadProvider to inject them. |
Action: Document this decision, and also make sure AnyPayloadProvider is understandable and discoverable. |
We should make the InvariantDataProvider support AnyProvider. The InvariantDataProvider is the one that returns
Default
impls for data structs.Currently,
Default
returns a sized type and therefore requires that we box it in anRc
when putting it into an AnyProvider. We should be able to instead make InvariantDataProvider support the CrabBake-like style of AnyProvider, which is a static reference.This would likely involve a trait that data structs implement which returns a
&'static T
. I propose that we use ConstDefault for this purpose. I tested and it works for our use case, assuming that we make all our objects const-constructible, which CrabBake requires anyway.Needs approval from:
The text was updated successfully, but these errors were encountered: