Crate serde_big_array
source · [−]Expand description
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.
Example
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[..]);
assert!(false);
}
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[..]);
}
Macros
Big array macro