Reversible<T>
A generic wrapper struct that provides reversible editing capabilities for values of type T: Default + Debug + Clone.
Features
- Tracks changes separately from the original data
- Only clones the original data when modifications begin (lazy cloning)
- Optional Serde support for serialization/deserialization (with
serdefeature) - Implements
AsRef<T>andAsMut<T>for transparent access to the original and changed data.
Design Purpose
This structure is useful for scenarios where you need:
- To track changes separately from original data
- Lazy cloning to avoid unnecessary clones
- Transparent access via
AsRef/AsMut - Optional (de)serialization of only the original state
Example
let mut rev = from;
assert_eq!;
*rev.as_mut = 13;
assert_eq!;
assert_eq!;
rev.save;
assert_eq!;
*rev.as_mut = 4;
assert_eq!;
assert_eq!;
rev.revert;
assert_eq!;