pub struct StateContext {
    current_state: CurrentState,
    behaviors: Vec<(CurrentState, Box<dyn IStateBehavior>)>,
}
Expand description

Implementation of the state machine. This maintains the context in which the state machine runs.

Fields§

§current_state: CurrentState

The current state of the machine.

§behaviors: Vec<(CurrentState, Box<dyn IStateBehavior>)>

Maps values from the CurrentState enumeration to instances of the IStateBehavior representing the behavior for that state. This vector owns the StateXXX struct instances.

Implementations§

source§

impl StateContext

source

pub fn new() -> StateContext

Constructor

Returns

Returns a new instance of the StateContext struct.

source

pub fn remove_comments(&mut self, text: &str) -> String

Entry point for callers to filter text. Removes Rust-style line and block comments from the text.

Parameters
  • text

    The text from which to remove comments.

Returns

Returns the text as a new string, without the comments.

source

fn set_next_state(&mut self, new_state: &CurrentState)

Helper method to transition the state machine to the specified state. Does nothing if the new state is the same as the old state.

Parameters
  • new_state

    A value from the CurrentState enumeration indicating the state to which to transition.

source

fn get_behavior(&mut self, state: &CurrentState) -> &mut Box<dyn IStateBehavior>

Helper method to retrieve the behavior corresponding to the given state. A behavior is an implementation of the IStateBehavior trait that can be called to get a new state. There is a different behavior for each state.

The behaviors are created as needed and cached in the StateContext struct.

Parameters
  • state

    A value from the CurrentState enumeration indicating which behavior to return.

Returns

Returns a mutable reference to a IStateBehavior instance representing the specified state.

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