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

Add support for arrays of arbitrary size (serde big array) #272

Merged
merged 5 commits into from
Mar 7, 2021
Merged

Conversation

jonasbb
Copy link
Owner

@jonasbb jonasbb commented Mar 7, 2021

Add support for arrays of arbitrary size.
This feature requires Rust 1.51+.

// Rust
#[serde_as(as = "[[_; 64]; 33]")]
value: [[u8; 64]; 33],
// JSON
"value": [[0,0,0,0,0,...], [0,0,0,...], ...],

Mapping of arrays was available before, but limited to arrays of length 32.
All conversion methods are available for the array elements.

This is similar to the existing serde-big-array crate with three important improvements:

  1. Support for the serde_as annotation.
  2. Supports non-copy elements (see serde-big-array#6).
  3. Supports arbitrary nestings of arrays (see serde-big-array#7).

Due to the const generics support it is now also possible to deserialize a map into an array of tuple elements.


@est31 The array initialization without Clone might also be suitable for serde-big-array.

Both generics can be significantly simplified and don't need to depend on DeserializeAsWrap.
This is gated on the const-generics support available in version 1.51+.
This includes basic nesting of types with serde_as and the conversion to a map.
The deserialization is partially unsafe since it writes into an
uninitialized array element by element.
The conversion from a map (in the serialized format) to an array of
tuples (in rust) is new and not available without const-generics
support.
@codecov
Copy link

codecov bot commented Mar 7, 2021

Codecov Report

Merging #272 (b3441a7) into master (2e14175) will decrease coverage by 0.46%.
The diff coverage is 39.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #272      +/-   ##
==========================================
- Coverage   77.17%   76.70%   -0.47%     
==========================================
  Files          36       40       +4     
  Lines        2129     2142      +13     
==========================================
  Hits         1643     1643              
- Misses        486      499      +13     
Impacted Files Coverage Δ
src/de/const_arrays.rs 0.00% <0.00%> (ø)
src/de/impls.rs 80.18% <ø> (+1.66%) ⬆️
src/de/mod.rs 83.33% <ø> (ø)
src/lib.rs 75.00% <ø> (ø)
src/ser/const_arrays.rs 0.00% <0.00%> (ø)
src/ser/impls.rs 97.91% <ø> (-0.20%) ⬇️
src/ser/mod.rs 60.00% <ø> (ø)
src/utils.rs 93.93% <ø> (ø)
tests/serde_as.rs 100.00% <ø> (ø)
tests/utils.rs 100.00% <ø> (ø)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e14175...b3441a7. Read the comment docs.

@jonasbb
Copy link
Owner Author

jonasbb commented Mar 7, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 7, 2021

Build succeeded:

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