serde-diff
A small helper that can
- Serialize the fields that differ between two structs of the same type
- Apply previously serialized field differences to other structs.
The SerdeDiff trait impl can serialize field paths recursively, greatly reducing the amount of data that needs to be serialized when only a small part of a struct has changed.
Usage
On a struct:
Serialize & apply differences for various formats:
rmp_serde (MessagePack - very small messages)
let msgpack_data = to_vec_named?;
let mut deserializer = new;
apply?;
bincode (very fast serialize/deserialize)
let bincode_data = serialize?;
config.deserialize_seed?;
serde_json
let json_data = to_string?;
let mut deserializer = from_str;
apply?;
Built-in type support
- Primitive types
- std::time::{Duration, SystemTime}
- IP addresses in std
- Vec
- HashMap (thanks @milkey-mouse)
- BTreeMap (thanks @milkey-mouse)
- Fixed-size arrays (thanks @Boscop)
- Tuples (thanks @Boscop)
Simple example
Cargo.toml
[]
= "0.2.0"
= "1"
= "1" # all serde formats are supported, serde_json is shown in this example
main.rs
use ;
use ;
Derive macro attributes
Opaque structs:
// opaque structs are serialized as a unit and fields do not need to implement SerdeDiff
Opaque fields:
Skip fields:
Contribution
All contributions are assumed to be dual-licensed under MIT/Apache-2.
License
Distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT.