pub struct MoveProcessor {}
Expand description

Represents the processor that translates the move list into a list of IMoveCommand objects then either displays them or executes them.

This struct uses a parser to convert the single letter characters in a string into a list of actions (instances of the MoveCommandXXX structs). This list of actions is then display or executed to perform the operations.

The process of executing the list of operations is an example of the “Command” pattern. The parsing step is also an example of the “Interpreter” pattern, where the actions are the tokens to be interpreted.

Implementations§

source§

impl MoveProcessor

source

pub fn new() -> MoveProcessor

Constructor

Returns

Returns a new instance of the MoveProcessor struct.

source

pub fn parse(&self, moves: &str) -> Vec<Box<dyn IMoveCommand>>

Parse the given list of move commands, where each command is represented by a single character, to produce a list of move command objects.

Recognizes ‘U’, ‘D’, ‘L’, and ‘R’ (case-insensitive). All other characters are assigned a “Do Nothing” (Null Object) command.

Parameters
  • moves

    A string containing the move commands to parse.

Returns

Returns a list of the move commands, with each command represented by the IMoveCommand trait.

source

pub fn show_commands(&self, commands: &Vec<Box<dyn IMoveCommand>>)

Display the given list of move commands.

Parameters
  • commands

    A list of IMoveCommand objects, each representing one move command.

source

pub fn execute_commands(&self, commands: &Vec<Box<dyn IMoveCommand>>)

Execute the given list of move commands. Execution amounts to a series of command names printed to standard out.

Parameters
  • commands

    A list of IMoveCommand objects, each representing one move command.

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