pub trait Modifier<T> {
type Change;
// Required methods
fn modify(&mut self, obj: &mut T) -> Self::Change;
fn undo(&mut self, change: &Self::Change, obj: &mut T);
fn redo(&mut self, change: &Self::Change, obj: &mut T);
// Provided methods
fn undo_meaning(&mut self, _change: &Self::Change) { ... }
fn redo_meaning(&mut self, _change: &Self::Change) { ... }
}Expand description
Modifies objects in a way that can be reversed.
§Change in meaning of modifier
When there are multiple modifiers in the same context, such as a list of modifiers, then one modification might change the meaning of another.
For example, when an item is insert into a list:
[0, 3], inserting at1changes to[0, 4](range includes index)[2, 4], inserting at0changes to[3, 5](range is after index)[0, 3], inserting at3changes to[0, 3](the same)
Meaning of a modifier is information that refers to information in the object. When the object changes, the consistency of the reference might require updating the modifier.
This is what the methods undo_meaning and redo_meaning do.
They preserve meaning even though the change originated from another modifier.
Required Associated Types§
Required Methods§
Sourcefn modify(&mut self, obj: &mut T) -> Self::Change
fn modify(&mut self, obj: &mut T) -> Self::Change
Modify an object and return the change.
This might be indeterministic.
Use redo_meaning for applying change in meaning of modifier.
Provided Methods§
Sourcefn undo_meaning(&mut self, _change: &Self::Change)
fn undo_meaning(&mut self, _change: &Self::Change)
Undo meaning change in the modifier introduced by a change.
This is called after undoing change by any modifier used in same context.
Sourcefn redo_meaning(&mut self, _change: &Self::Change)
fn redo_meaning(&mut self, _change: &Self::Change)
Redo meaning change in the modifier.
This is called after modification by any modifier used in same context.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".