blizz-fsm 3.0.0-beta.3

Generic state machine engine for sequential state processing
Documentation
use crate::input::Action;

/// Completion payload returned by a state when it finishes.
///
/// `output` carries an optional key-value pair to store in the machine's
/// result map. `then` holds continuation states to splice into the front
/// of the queue before the machine pops its next state.
pub struct StateResult<S: ?Sized> {
  pub output: Option<(String, String)>,
  pub then: Vec<Box<S>>,
}

/// A single step in a state machine, generic over context type `Ctx` and
/// the object-safe state marker `S`.
///
/// Returns `None` while still active, or `Some(StateResult)` when done.
pub trait State<Ctx, S: ?Sized> {
  fn tick(&mut self, ctx: &Ctx) -> Option<StateResult<S>>;
  fn handle_action(&mut self, action: Action, ctx: &Ctx) -> Option<StateResult<S>>;

  fn on_enter(&mut self, _ctx: &Ctx) {}
  fn on_exit(&mut self, _ctx: &Ctx) {}
}