Test case:
use serde::{Deserialize, Serialize};
use std::io::Write;
#[derive(Debug, Deserialize, Serialize)]
enum Thing {
Thing1(String),
Thing2(u64),
Thing3(Box<[Thing]>),
Thing4,
}
fn main() -> anyhow::Result<()> {
let thing = Thing::Thing3(vec![Thing::Thing2(42), Thing::Thing4].into_boxed_slice());
let v = serde_cbor::ser::to_vec_packed(&thing)?;
std::fs::File::create("cbor")?.write_all(&v)?;
Ok(())
}
Hex dump of the resulting file:
00000000 a1 66 54 68 69 6e 67 33 82 a1 66 54 68 69 6e 67 |.fThing3..fThing|
00000010 32 18 2a 03 |2.*.|
Notice that it includes Thing3 and Thing2, but not Thing4.
From what I can tell, the serialization of unit variants pays attention to self.packed, but the serialization of non-unit variants does not.