bad_serialization/
bad-serialization.rs

1use procspawn::{self, serde::Json, spawn};
2use serde::{Deserialize, Serialize};
3
4#[derive(Serialize, Deserialize, Debug)]
5struct InnerStruct {
6    value: u64,
7}
8
9#[derive(Serialize, Deserialize, Debug)]
10struct BadStruct {
11    #[serde(flatten)]
12    inner: InnerStruct,
13}
14
15fn main() {
16    procspawn::init();
17
18    // json works:
19    println!("JSON lets you send a flattened object through:");
20    let handle = spawn((), |()| {
21        Json(BadStruct {
22            inner: InnerStruct { value: 42 },
23        })
24    });
25    println!("result with JSON: {:?}", handle.join());
26
27    println!("raw bincode currently does not permit this:");
28    // bincode fails:
29    let handle = spawn((), |()| BadStruct {
30        inner: InnerStruct { value: 42 },
31    });
32    println!("result with bincode: {:?}", handle.join());
33}