Crates.io | simple-undo |
lib.rs | simple-undo |
version | 0.1.1 |
source | src |
created_at | 2021-10-22 19:20:30.233757 |
updated_at | 2021-11-22 23:18:40.821877 |
description | Easy to use undo-redo library |
homepage | |
repository | https://github.com/didibear/simple-undo |
max_upload_size | |
id | 469509 |
size | 11,178 |
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 !");
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.