-
-
Notifications
You must be signed in to change notification settings - Fork 774
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
Add "const-generics" feature #1860
Conversation
If this change is desirable, I will fix and add more tests. If not, feel free to close this PR. |
A way to avoid breakage is to use |
Tried to create a more robust array creation procedure based on the feedback of rust-lang/rust#75644 but looks like the new That said, it is just a matter of bumping the minimal compiler version and 1.31 (2018) should probably be a good choice. |
serde's maintainer has gone to great lengths to avoid bumping the MSRV of serde proper. You could try moving the offending code into a separate module in a separate file, and put the |
@est31 This module strategy is new to me. Thanks for the suggestion! I am still not sure if |
With your PR as is, if any crate in compilation graph enables If I were you, I'd explore following approach (note it is pseudocode): struct Helper<T>;
impl<T> Helper<T> {
default fn serialize(val: T, ser: Serializer) {
panic!()
}
}
impl<T: Serialize> Helper<T> {
fn serialize(val: T, ser: Serializer) {
val.serialize(ser)
}
}
impl<T> Default for Helper<T> where T: Serialize {...}
impl<T, const N> Serialize for [T; N] where [Helper<T>; N]: Default {
fn serialize(self, ser: Serializer) {
for item in self {
Helper<T>::serialize(item);
}
}
} It relies on rust-lang/rust#74254 merged first. However, if it works, no breakage occurs. |
@MikailBag There are some projects that provide unstable features where stability guarantees aren't preserved and I though the same could be done with serde because specialization is something that probably won't be stabilized in the near future. Hopefully, constant generics will be ready for the 1.49 release. |
@dtolnay Looks like strict semver is desirable and there is no way around the |
As far as I understand, |
From my understanding, marker traits are also needed, not just specialization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll close this and suggest that people use https://github.com/est31/serde-big-array for now.
I would like to follow along in rust-lang/rust#61415 + rust-lang/rust#76560 + rust-lang/rust#44580 a while longer before setting what approach to land in this crate.
Thanks anyway!
Thanks for the prompt response |
Brings an opt-in breaking change because
T
of[T; 0]
Serialize/Deserialize implementation doesn't requireT: Serialize/Deserialize
bounds. This scenario has the same root cause of stdDefault
implementation for[T; N]
.