Trait Modifier

Source
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 at 1 changes to [0, 4] (range includes index)
  • [2, 4], inserting at 0 changes to [3, 5] (range is after index)
  • [0, 3], inserting at 3 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.

Required Associated Types§

Source

type Change

The change applied to an object.

Required Methods§

Source

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.

Source

fn undo(&mut self, change: &Self::Change, obj: &mut T)

Undo change made to an object.

Required to be deterministic.

Source

fn redo(&mut self, change: &Self::Change, obj: &mut T)

Redo change made to an object.

Required to be deterministic.

Provided Methods§

Source

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.

Source

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.

Implementations on Foreign Types§

Source§

impl<T, U: Modifier<T>> Modifier<T> for Vec<U>

Source§

type Change = (usize, <U as Modifier<T>>::Change)

Source§

fn modify(&mut self, obj: &mut T) -> Self::Change

Source§

fn undo(&mut self, change: &Self::Change, obj: &mut T)

Source§

fn redo(&mut self, change: &Self::Change, obj: &mut T)

Source§

fn undo_meaning(&mut self, change: &Self::Change)

Source§

fn redo_meaning(&mut self, change: &Self::Change)

Implementors§

Source§

impl<T, M, U> Modifier<T> for ModifyOptimizer<M, U>
where M: Modifier<T>, U: Utility<T>, M::Change: Clone,

Source§

type Change = Vec<<M as Modifier<T>>::Change>