reversible 0.1.2

A generic wrapper struct that provides reversible editing capabilities..
Documentation
  • Coverage
  • 66.67%
    6 out of 9 items documented4 out of 8 items with examples
  • Size
  • Source code size: 7.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 219.1 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • p4ymak/reversible
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • p4ymak

Reversible<T>

Latest version

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 serde feature)
  • Implements AsRef<T> and AsMut<T> for transparent access to the original and changed data.

Example

let mut rev = Reversible::from(4);
assert_eq!(rev.as_mut(), &mut 4);

*rev.as_mut() = 13;
assert_eq!(rev.as_ref(), &4);
assert_eq!(rev.as_mut(), &mut 13);

rev.save();
assert_eq!(rev.as_ref(), &13);

*rev.as_mut() = 4;
assert_eq!(rev.as_ref(), &13);
assert_eq!(rev.as_mut(), &mut 4);

rev.revert();
assert_eq!(rev.as_mut(), &mut 13);