pro-serde-versioned
This crate provides a simple method for versioning and upgrading data structures
when serialized via [serde].
Features
- The
VersionedSerializeandVersionedDeserializetraits allow deriving stable serialization methods for an enum, which will still work if new enum cases are added in the future - The
VersionedUpgradetrait defines a enum sequence of struct generations by providing a method to upgrade any struct in the sequence to the latest.
VersionedSerialize/VersionedDeserialize Examples
use ;
use ;
// Let's say you have two generations of some serialized data structure ...
;
// Derive [`VersionedSerialize`] and [`VersionedDeserialize`]
let versioned_struct: MyStructVersioned =
MyStructV1 .into;
// Serializing `MyStructV1` to `serde_json::Value` format
let serialized_v1: Value = versioned_struct.versioned_serialize?;
// Deserialize `MyStructVersion` from JSON format
let deserialized_v1 = versioned_deserialize?;
assert_eq!;
# Ok::
VersionedUpgrade Examples
use ;
// Given the same two generations of a serialized data structure ...
;
// ... and an impl for the `Upgrade` trait which links them together ...
// Derive the [`VersionedUpgrade`] trait on a wrapper enum
// Now any struct can be upgraded to the latest enum of [`MyStructVersioned`]!
// Upgrade `MyStructV1` to `MyStructV2`.
let upgraded_v2 =
V1.upgrade_to_latest;
assert_eq!;
# Ok::