MutableCommand

Trait MutableCommand 

Source
pub trait MutableCommand {
    type Context;

    // Required methods
    fn execute(&self, ctx: &mut Self::Context);
    fn undo(&self, ctx: &mut Self::Context);

    // Provided methods
    fn redo(&self, ctx: &mut Self::Context) { ... }
    fn description(&self) -> Cow<'_, str> { ... }
}
Expand description

A trait representing a mutable command that can be executed, undone, and redone.

§Associated Types

  • Context: The type of the context in which the command operates.

§Required Methods

  • execute(&self, ctx: &mut Self::Context): Executes the command in the given context.
  • undo(&self, ctx: &mut Self::Context): Undoes the command in the given context.

§Provided Methods

  • redo(&self, ctx: &mut Self::Context): Redoes the command by calling execute again. This method can be overridden if needed.
  • description(&self) -> Cow<str>: Returns a description of the command. The default implementation returns “Unknown command”.

Required Associated Types§

Required Methods§

Source

fn execute(&self, ctx: &mut Self::Context)

Executes the command in the given context.

§Arguments
  • ctx - A mutable reference to the context in which the command operates.
Source

fn undo(&self, ctx: &mut Self::Context)

Undoes the command in the given context.

§Arguments
  • ctx - A mutable reference to the context in which the command operates.

Provided Methods§

Source

fn redo(&self, ctx: &mut Self::Context)

Redoes the command by calling execute again. This method can be overridden if needed.

§Arguments
  • ctx - A mutable reference to the context in which the command operates.
Source

fn description(&self) -> Cow<'_, str>

Returns a description of the command. The default implementation returns “Unknown command”.

§Returns

A string slice that holds the description of the command.

Implementors§