struct MementoContext {
    undo_list: Vec<Memento>,
}
Expand description

This struct creates a context around the undo list that the memento_exercise() executes within. This gets around the problem of needing a static undo list as all the methods on this context have ready access to the undo list in the context.

Fields§

§undo_list: Vec<Memento>

The list of memento objects that form a series of snapshots in time of a MementoTextObject.

Implementations§

source§

impl MementoContext

source

fn new() -> MementoContext

Constructor.

source

fn save_for_undo(&mut self, text_object: &MementoTextObject, operation: &str)

Take a snapshot of the given text object associated with the name of given operation.

Parameters
  • text_object

    The MementoTextObject to take a snapshot of.

  • operation

    A string describing the operation that will be applied after the snapshot is taken.

source

fn operation_replace( &mut self, text_object: &mut MementoTextObject, search_pattern: &str, replace_text: &str )

An operation to search and replace text in a MementoTextObject.

Parameters
  • text_object

    The MementoTextObject to work with.

  • search_pattern

    What to look for in the MementoTextObject

  • replace_text

    What to replace the search_pattern with

source

fn operation_reverse(&mut self, text_object: &mut MementoTextObject)

An operation to reverse the characters in the given MementoTextObject.

Parameters
  • text_object

    The MementoTextObject to work with.

source

fn undo(&mut self, text_object: &mut MementoTextObject)

Perform an undo on the given Command_TextObject, using the mementos in the “global” undo list. If the undo list is empty, nothing happens.

Parameters
  • text_object

    The MementoTextObject to update.

source

fn apply_replace_operation( &mut self, text_object: &mut MementoTextObject, search_pattern: &str, replace_text: &str )

Helper function to replace a pattern with another string in the given MementoTextObject after adding a snapshot of the text object to the undo list. Finally, it shows off what was done.

Parameters
  • text_object

    The MementoTextObject to update.

  • search_pattern

    What to look for in the MementoTextObject

  • replace_text

    What to replace the search_pattern with

source

fn apply_reverse_operation(&mut self, text_object: &mut MementoTextObject)

Helper function to reverse the order of the characters in the given MementoTextObject after adding a snapshot of the text object to an undo list. Finally, it shows what was done.

Parameters
  • text_object

    The MementoTextObject to work with.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

source§

fn vzip(self) -> V