A flexible data enum guaranteeing strict variant ordering for backward-compatible binary serialization.
I found myself making a similar data type quite often for serialized communication of flexible values. At the same time, when working with serialization formats that are not self-describing, reordering enum variants is a footgun that is easy to overlook. This crate has strict tests to maintain variant ordering.
- Assertions to protect backward compatibility.
- Safe methods for checked conversion of integer/float types.
Cowfor slice-type variants (BytesandText) for zero-copy deserialization.- (
serdefeature) De/serialization via serde. - (
ownedfeature) Self-referentialOwnedDataCellwhich supports deserializing from an owned buffer without copying, using theyokecrate.
It's surprisingly hard to do zero-copy deserialization from an
owned buffer right, as you essentially need a 'self lifetime to
borrow from self, which requires either Box::leak(...) or
Pin<Box<...>> to get a static lifetime. Then, once you have a static
lifetime to self-referenced data, you need to narrow the static
lifetime to preserve soundness. Thankfully yoke handles the
safety of self-reference and lifetime narrowing which avoids
needing to manually ensure soundness of self-referential data.
Licensed under the MIT license.