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:
- Check if in final state → AlreadyFinal
- Find matching rules for (from, event)
- No rules → check event policy (Reject/Ignore)
- Evaluate guards top-to-bottom, first passing wins
- Execute callbacks: on_exit → on_transition → on_enter
- Run invariants on new context
- Record history