#serde #array #arrays #big

serde-big-array

Big array helper for serde

10 releases

0.3.2 Mar 11, 2021
0.3.1 Dec 28, 2020
0.3.0 May 2, 2020
0.2.0 Oct 2, 2019
0.1.3 Dec 29, 2018
Download history 7202/week @ 2021-08-11 6711/week @ 2021-08-18 7490/week @ 2021-08-25 8220/week @ 2021-09-01 7346/week @ 2021-09-08 8181/week @ 2021-09-15 9910/week @ 2021-09-22 6845/week @ 2021-09-29 11230/week @ 2021-10-06 13058/week @ 2021-10-13 15922/week @ 2021-10-20 9993/week @ 2021-10-27 10522/week @ 2021-11-03 8789/week @ 2021-11-10 11107/week @ 2021-11-17 11039/week @ 2021-11-24

43,413 downloads per month
Used in 92 crates (57 directly)

MIT/Apache

14KB
148 lines

serde-big-array

docs crates.io dependency status

Big array helper for serde. The purpose of this crate is to make (de-)serializing arrays of sizes > 32 easy. This solution is needed until serde adopts const generics support.

Bases on this snippet.

extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[macro_use]
extern crate serde_big_array;

big_array! { BigArray; }

#[derive(Serialize, Deserialize)]
struct S {
    #[serde(with = "BigArray")]
    arr: [u8; 64],
}

#[test]
fn test() {
    let s = S { arr: [1; 64] };
    let j = serde_json::to_string(&s).unwrap();
    let s_back = serde_json::from_str::<S>(&j).unwrap();
    assert!(&s.arr[..] == &s_back.arr[..]);
}

If you enable the const-generics feature, you won't have to invoke the big_array macro any more:

#[macro_use]
extern crate serde_derive;
use serde_big_array::BigArray;

#[derive(Serialize, Deserialize)]
struct S {
    #[serde(with = "BigArray")]
    arr: [u8; 64],
}

#[test]
fn test() {
    let s = S { arr: [1; 64] };
    let j = serde_json::to_string(&s).unwrap();
    let s_back = serde_json::from_str::<S>(&j).unwrap();
    assert!(&s.arr[..] == &s_back.arr[..]);
}

Important links:

MSRV

The minimum supported Rust version (MSRV) is Rust 1.32.0.

License

This crate is distributed under the terms of both the MIT license and the Apache License (Version 2.0), at your option.

See LICENSE-APACHE and LICENSE-MIT for details.

License of your contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.5–1.2MB
~27K SLoC