struct CommandContext {
    command_list: Vec<Box<dyn ICommand>>,
}
Expand description

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

Fields§

§command_list: Vec<Box<dyn ICommand>>

The list of command objects that describe the changes made to the text object.

Implementations§

source§

impl CommandContext

source

fn new() -> CommandContext

Constructor.

source

fn execute_and_save( &mut self, command: Box<dyn ICommand>, text: &mut CommandTextObject )

Execute the given command on the given text object then save the command on the given undo list.

Parameters
  • command_list

    The list that holds the commands for later undoing.

  • command

    The command to apply to the text.

  • text

    The CommandTextObject to affect.

source

fn apply_replace_command( &mut self, text: &mut CommandTextObject, search_pattern: &str, replace_text: &str )

Helper method to create a Command object that replaces text in the given CommandTextObject, applies the command to the CommandTextObject, and then adds the command to the given undo list. Finally, it shows off what was done.

Parameters
  • command_list

    The list that holds the commands for later undoing.

  • text

    The CommandTextObject to affect.

  • search_pattern

    What to look for in the CommandTextObject.

  • replace_text

    What to replace search_pattern with.

source

fn apply_reverse_command(&mut self, text: &mut CommandTextObject)

Helper method to create a Command object that reverses the order of the characters in the given CommandTextObject, applies the command to the CommandTextObject, and then adds the command to the given undo list. Finally, it shows what was done.

Parameters
  • command_list

    The list that holds the commands for later undoing.

  • text

    The CommandTextObject to affect.

source

fn undo(&mut self, text: &mut CommandTextObject)

Perform an undo on the given CommandTextObject, using the commands in the given undo list. If the undo list is empty, nothing happens.

Parameters
  • command_list

    The list that holds the commands for later undoing.

  • text

    The CommandTextObject to affect.

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