Struct simple_undo::Undo[][src]

pub struct Undo<TState> { /* fields omitted */ }
Expand description

The Undo type wrapping a state that tracks updates and allows undoing or redoing them.

Implementations

Wraps the given state in an Undo, which will track all updates and allows undoing or redoing them.

Example
use simple_undo::Undo;

let mut wrapper = Undo::new(5);

Unwraps the inner state to an owned value, disabling the undo/redo feature.

Example
let mut message = Undo::new(String::new());
message.update(|text| text.push_str("Hello "));
message.update(|text| text.push_str("world !"));

let result: String = message.unwrap();
assert_eq!(result, "Hello world !");

Updates the current state with the given mutating function.

Note that future Undo::redo are reset.

Example
let mut counter = Undo::new(0);
counter.update(|value| *value += 10);
counter.update(|value| *value -= 5);
counter.update(|value| *value += 3);
assert_eq!(*counter, 8);

Undo the last update done to the current state.

Example
let mut counter = Undo::new(0);
counter.update(|value| *value += 1);
counter.update(|value| *value += 2);
assert_eq!(*counter, 3);

counter.undo();
assert_eq!(*counter, 1);
counter.undo();
assert_eq!(*counter, 0);
counter.undo(); // does nothing
assert_eq!(*counter, 0);

Redo the last update that have been undone using Undo::undo.

Example
let mut counter = Undo::new(0);
counter.update(|value| *value += 1); // 1
counter.update(|value| *value += 2); // 3
counter.undo(); // 1
counter.undo(); // 0
assert_eq!(*counter, 0);

counter.redo();
assert_eq!(*counter, 1);
counter.redo();
assert_eq!(*counter, 3);
counter.redo(); // does nothing
assert_eq!(*counter, 3);

Trait Implementations

The resulting type after dereferencing.

Dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.