Skip to content

Commit

Permalink
Support mode that doesn't override defaults
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
est31 committed Oct 2, 2019
1 parent 06117e3 commit 64b2529
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,17 @@ macro_rules! big_array {
}
)+
};
($name:ident;) => {
($name:ident; + $($len:expr,)*) => {
big_array! {
$name;
40, 48, 50, 56, 64, 72, 96, 100, 128, 160, 192, 200, 224, 256, 384, 512,
768, 1024, 2048, 4096, 8192, 16384, 32768, 65536,
$($len,)*
}
};
($name:ident;) => {
big_array! {
$name; +
}
}
}
27 changes: 27 additions & 0 deletions tests/plus.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![no_std]

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

big_array! { BigArray; +127, }

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

#[test]
fn test() {
let s = S { arr: [1; 64], arr_2: [1; 127] };
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!(&s.arr_2[..] == &s_back.arr_2[..]);
}

0 comments on commit 64b2529

Please sign in to comment.