I'm trying to make some structures serialize into bytes in a nice way. However, these types contain both optional data and maps of bytes (Option<Vec<u8>> and BTreeMap<usize, Vec<u8>>). #[serde(with = "serde_bytes")] doesn't seem capable of dealing with these types. I've found a way to make them work by changing the types to Option<ByteBuf> and BTreeMap<usize, ByteBuf>, but it adds quite a lot of extra glue code. Is there a nicer way to achieve this?
I'm trying to make some structures serialize into bytes in a nice way. However, these types contain both optional data and maps of bytes (
Option<Vec<u8>>
andBTreeMap<usize, Vec<u8>>
).#[serde(with = "serde_bytes")]
doesn't seem capable of dealing with these types. I've found a way to make them work by changing the types toOption<ByteBuf>
andBTreeMap<usize, ByteBuf>
, but it adds quite a lot of extra glue code. Is there a nicer way to achieve this?