pub trait MachineState<P>:
Send
+ Sync
+ 'static
+ Anywhere
P: IntoScriptPluginParams,{
// 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§
Sourcefn poll_next(
&mut self,
ctxt: &MachineContext,
world: &mut World,
) -> Box<dyn Future<Output = Result<Box<dyn MachineState<P>>, ScriptError>> + Send + Sync>
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.
Sourcefn trigger_event(&mut self, world: &mut World)
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§
Sourcefn state_name(&self) -> &'static str
fn state_name(&self) -> &'static str
A readable state name
Sourcefn is_final(&self) -> bool
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
Sourcefn build_script_error_event(
&self,
attachment: &ScriptAttachment,
base_error: ScriptError,
) -> ScriptErrorMessage
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".