Provides undo-redo functionality with dynamic dispatch and automatic command merging.
merge!
] macro or the [merge
] method.
When two commands are merged, undoing and redoing them are done in a single step.display
feature is enabled.chrono
feature is enabled.Add this to Cargo.toml
:
toml
[dependencies]
undo = "0.28"
And this to main.rs
:
```rust extern crate undo;
use undo::{Command, Record};
struct Add(char);
impl Command
fn undo(&mut self, s: &mut String) -> Result<(), Box<dyn Error + Send + Sync>> {
self.0 = s.pop().ok_or("`s` is empty")?;
Ok(())
}
}
fn main() -> Result<(), Box
record.undo().unwrap()?;
record.undo().unwrap()?;
record.undo().unwrap()?;
assert_eq!(record.as_receiver(), "");
record.redo().unwrap()?;
record.redo().unwrap()?;
record.redo().unwrap()?;
assert_eq!(record.as_receiver(), "abc");
Ok(())
} ```
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.