simple-undo 0.1.1

Easy to use undo-redo library
Documentation
  • Coverage
  • 100%
    7 out of 7 items documented6 out of 7 items with examples
  • Size
  • Source code size: 10.86 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.42 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • didibear/simple-undo
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • DidiBear

Simple undo

An easy to use undo-redo library:

use simple_undo::Undo;

let mut message = Undo::new(String::new());
message.update(|text| text.push_str("Simple "));
message.update(|text| text.push_str("undo !"));
assert_eq!(*message, "Simple undo !");

message.undo(); // "Simple "
message.undo(); // ""
message.redo(); // "Simple "

message.update(|text| text.push_str("redo !"));
assert_eq!(*message, "Simple redo !");

let result: String = message.unwrap();
assert_eq!(result, "Simple redo !");

How it works

Undo wraps the given state and keeps one copy of it. When [Undo::undo] is called, the previous state is re-created by re-applying the n-1 updates to the initial state.

If you need better performance, please consider alternatives such as undo or rundo crates, which allow you to define or generate the actual undo operation.