scamper/transition

Transition engine for scamper FSMs.

Handles guard evaluation, callback execution, invariant checking, and rollback on failure. This is the core algorithmic module.

Types

Result of a successful transition execution.

pub type TransitionResult(state, event, context) {
  TransitionResult(
    state: state,
    context: context,
    history: List(history.TransitionRecord(state, event, context)),
    entered_at: Int,
  )
}

Constructors

  • TransitionResult(
      state: state,
      context: context,
      history: List(history.TransitionRecord(state, event, context)),
      entered_at: Int,
    )

Values

pub fn available_events(
  state: state,
  config: config.Config(state, context, event),
) -> List(event)

Get all events that have at least one matching transition rule from the current state. Does not evaluate guards.

pub fn can_execute(
  state: state,
  event: event,
  context: context,
  config: config.Config(state, context, event),
) -> Bool

Check whether a transition is possible without executing it. Only checks final state, matching rules, and guards.

pub fn execute(
  state: state,
  context: context,
  event: event,
  config: config.Config(state, context, event),
  current_history: List(
    history.TransitionRecord(state, event, context),
  ),
) -> Result(
  TransitionResult(state, event, context),
  error.TransitionError(state, event),
)

Execute a state transition.

Algorithm:

  1. Check if in final state → AlreadyFinal
  2. Find matching rules for (from, event)
  3. No rules → check event policy (Reject/Ignore)
  4. Evaluate guards top-to-bottom, first passing wins
  5. Execute callbacks: on_exit → on_transition → on_enter
  6. Run invariants on new context
  7. Record history
Search Document