I have a type Foo
which contains a big array. With the help of serde_big_array
, serde_derive
, and serde_with
, I can derive serialization and deserializalization.
use serde_big_array;
use serde_big_array::BigArray;
use serde_derive::{Deserialize, Serialize};
pub const SIZE: usize = 30000;
#[derive(Clone, Debug, Serialize, Deserialize)]
struct Foo {
#[serde(with = "BigArray")]
pub vals: [bool; SIZE],
}
This works fine.
However, when use this type in another structure I run into trouble.
#[derive(Clone, Debug, Serialize, Deserialize)]
struct Bar {
field0: Foo,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn deserialization_attempt_test() {
let foo = Foo {
vals: [false; SIZE],
};
let instance: Bar = Bar { field0: foo };
let json = serde_json::to_string(&instance).unwrap();
println!("PMD0");
let s_back = serde_json::from_str::<Bar>(&json).unwrap();
println!("PMD1");
}
}
Running this tests with cargo t deserialization_attempt_test -- --nocapture
prints PMD0
but not PMD1
. The test fails with the message
thread 'tests::deserialization_attempt' has overflowed its stack
fatal runtime error: stack overflow
How do I implement Serialize
and Deserialize
for Bar
?