-
Notifications
You must be signed in to change notification settings - Fork 261
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 array serialization impls #371
Conversation
@ryanleh I recently started re-working an oldish PR to replace some parts of the code with const generics: I have a draft of the changes to bigint crate here: #372. Otherwise |
@mmagician Ah, had totally missed that const generics had stabilized!! 😁 That definitely makes more sense -- I updated the PR appropriately. |
serialize/src/lib.rs
Outdated
} | ||
} | ||
|
||
impl<T: CanonicalDeserialize + Default + Copy, const N: usize> CanonicalDeserialize for [T; N] { |
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 believe we can use new array methods to eliminate the Default + Copy
bounds:
Ok([(); N].map(|_| T::deserialize(&mut reader).unwrap()))
There is a downside that this panics immediately if there's an error, but that's not necessarily a bad thing. This might be the best we can do until this feature is stabilized.
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.
Awesome! I changed de-serialization to do this, removed the extra bounds, and added a TODO
to update things once the feature is stabilized.
For some reason the |
Should be fixed in the latest commit |
Description
This PR impls
CanonicalSerialize
andCanonicalDeserialize
for arrays of up to size 32. This is useful for deriving these traits on structs which contain arrays.I put
Default
andCopy
bounds onCanonicalDeserialize
in order to initialize the initial empty array. We could get rid of these bounds and use anOption<T>
, but I believe this necessitates heap allocation in order to unwrap theOption<T>
for the final result which I thought best to avoid. Let me know what y'all think is best.I'll complete the other TODOs once I get some form of approval from maintainers to move forward (not sure who to ask for review 😁 )
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
Pending
section inCHANGELOG.md
Files changed
in the GitHub PR explorer