Skip to content

Commit

Permalink
Support paths as well
Browse files Browse the repository at this point in the history
Fixes #5
  • Loading branch information
est31 committed Oct 2, 2019
1 parent 9ece314 commit 06117e3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ struct S {
*/
#[macro_export]
macro_rules! big_array {
($name:ident; $($len:tt,)+) => {
($name:ident; $($len:expr,)+) => {
pub trait $name<'de>: Sized {
fn serialize<S>(&self, serializer: S) -> $crate::reex::result::Result<S::Ok, S::Error>
where S: $crate::reex::Serializer;
Expand Down
28 changes: 28 additions & 0 deletions tests/const_path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![no_std]

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

mod module {
pub const NUMBER: usize = 127;
}

big_array! { BigArray; module::NUMBER, }

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

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

0 comments on commit 06117e3

Please sign in to comment.