Deser: Rethinking Rust Serialization
4 hours ago
- Serde has limitations due to its design, including poor interactions with internally tagged enums, flatten, and arbitrary precision features.
- Deser is a new serialization library that reverses Serde's architecture, using a sink/emitter model with heap-based state to avoid recursion and enable streaming.
- Deser supports self-describing formats like JSON, YAML, TOML, XML, and CBOR, but not non-self-describing ones like protobuf.
- Deser's design avoids in-band signalling for extensions (e.g., arbitrary precision, datetimes) and provides better error locations.
- Deser offers adapters and validators (e.g., Hex, DisplayFromStr, Check) that compose cleanly with generics.
- XML namespace handling and untagged enum buffering are improved in Deser compared to Serde.
- Performance is mixed: Deser reads ~10% slower than serde_json on average, but compiles faster and has better binary bloat.
- Deser uses unsafe internally for heap-allocated sinks, but is considered safe with modern tooling.
- The biggest cost is that Deser is not Serde, so ecosystem compatibility is limited.