serde_big_array/
lib.rs

1/*!
2Big array helper for serde.
3The purpose of this crate is to make (de-)serializing arrays of sizes > 32 easy.
4This solution is needed until [serde adopts const generics support](https://github.com/serde-rs/serde/issues/1937).
5
6This crates provides you with two tools to use big arrays in your crate:
7
8* The first tool is the [`BigArray`] trait. You can use it together with the
9  `serde_derive` macro and an `#[serde(with = "BigArray")]` next to your data declaration.
10* The second tool is the [`Array`] struct. It requires you to change your datastructures,
11  and some of the code accessing your array, but it allows for nested use cases,
12  which [`BigArray`] struggles with.
13
14We recommended using the [`BigArray`] trait in most cases, and using the
15[`Array`] struct only if [`BigArray`] doesn't work.
16
17[`BigArray`]: self::BigArray
18[`Array`]: self::Array
19
20## Example
21```
22extern crate serde;
23#[macro_use]
24extern crate serde_derive;
25extern crate serde_json;
26extern crate serde_big_array;
27
28use serde_big_array::BigArray;
29
30#[derive(Serialize, Deserialize)]
31struct S {
32    #[serde(with = "BigArray")]
33    arr: [u8; 64],
34}
35
36#[test]
37fn test() {
38    let s = S { arr: [1; 64] };
39    let j = serde_json::to_string(&s).unwrap();
40    let s_back = serde_json::from_str::<S>(&j).unwrap();
41    assert!(&s.arr[..] == &s_back.arr[..]);
42    assert!(false);
43}
44
45# fn main() {}
46```
47*/
48#![no_std]
49
50mod array;
51pub(crate) mod const_generics;
52pub use array::Array;
53pub use const_generics::BigArray;