Skip to main content

MachineState

Trait MachineState 

Source
pub trait MachineState<P>:
    Send
    + Sync
    + 'static
    + Any{
    // Required methods
    fn poll_next(
        &mut self,
        ctxt: &MachineContext,
        world: &mut World,
    ) -> Box<dyn Future<Output = Result<Box<dyn MachineState<P>>, ScriptError>> + Send + Sync>;
    fn trigger_event(&mut self, world: &mut World);

    // Provided methods
    fn state_name(&self) -> &'static str { ... }
    fn is_final(&self) -> bool { ... }
    fn build_script_error_event(
        &self,
        attachment: &ScriptAttachment,
        base_error: ScriptError,
    ) -> ScriptErrorMessage { ... }
}
Expand description

Describes a state in a finite state machine

Required Methods§

Source

fn poll_next( &mut self, ctxt: &MachineContext, world: &mut World, ) -> Box<dyn Future<Output = Result<Box<dyn MachineState<P>>, ScriptError>> + Send + Sync>

Polls the machine for the next state.

Machines are allowed to take multiple frames in generating it.

Source

fn trigger_event(&mut self, world: &mut World)

Triggers an event corresponding to this machine state, the reason we need to repeat this logic in every implementation is that Event is not dyn safe.

Implementors should emit their own type.

Provided Methods§

Source

fn state_name(&self) -> &'static str

A readable state name

Source

fn is_final(&self) -> bool

Final states designate that a state machine should complete processing. Returning true will cause the state to be recognize as a final state

Source

fn build_script_error_event( &self, attachment: &ScriptAttachment, base_error: ScriptError, ) -> ScriptErrorMessage

Build script error event with the most context possible

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§