Trait utility_programming::Modifier
[−]
[src]
pub trait Modifier<T> { type Change; 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); fn undo_meaning(&mut self, _change: &Self::Change) { ... } fn redo_meaning(&mut self, _change: &Self::Change) { ... } }
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 at1
changes to[0, 4]
(range includes index)[2, 4]
, inserting at0
changes to[3, 5]
(range is after index)[0, 3]
, inserting at3
changes 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.
Associated Types
type Change
The change applied to an object.
Required Methods
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.
fn undo(&mut self, change: &Self::Change, obj: &mut T)
Undo change made to an object.
Required to be deterministic.
fn redo(&mut self, change: &Self::Change, obj: &mut T)
Redo change made to an object.
Required to be deterministic.
Provided Methods
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.
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.