pub trait UndoRedoCommand: 'static {
// Required methods
fn name(&self) -> &str;
fn do_it(&mut self);
fn undo_it(&mut self);
fn as_any_mut(&mut self) -> &mut dyn Any;
}Expand description
A named, reversible operation.
Implement this trait to participate in the shared undo/redo stack.
The do_it / undo_it methods are called by UndoBuffer on redo and
undo respectively.
as_any_mut is the escape hatch for in-stroke coalescing — see
UndoBuffer::try_coalesce_last. Implementations downcast the
top-of-stack command back to their concrete type and merge a fresh
same-stroke action into the existing one (replacing its after
snapshot) instead of pushing a new command. Required so multi-event
strokes — slider drag, node drag, typing into a number field — land
as a single undo step.
Every implementor must provide as_any_mut — typically the one-liner
{ self }. Commands that don’t want coalescing leave the method
alone; their try_coalesce_last predicate just returns false and
add_and_do runs the usual path.
Required Methods§
Sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Downcast hook for in-stroke coalescing. Implementors forward
self; the predicate passed to UndoBuffer::try_coalesce_last
runs cmd.as_any_mut().downcast_mut::<ConcreteType>() to inspect
the top of the stack.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".