Skip to main content

Module state_machine

Module state_machine 

Source
Expand description

Generic state machine infrastructure for domain state machines.

Phase 0 generic base for the state_machine.rs generator (Category C).

Every generated {Name}StateMachine used to re-define the same structural boilerplate. This module provides:

  • StateMachineError — shared error type (identical across all modules)
  • TransitionMeta<S> — required trait for Transition enums
  • StateMachineBehavior — trait with default impls for all mechanical methods

Generated files collapse to:

ⓘ
use backbone_core::state_machine::{
    StateMachineError, StateMachineBehavior, TransitionMeta,
};

pub enum AgentState { PendingVerification, Active, Terminated }
pub enum AgentTransition { Approve, Suspend, Terminate }

impl TransitionMeta<AgentState> for AgentTransition {
    fn target_state(&self) -> AgentState { ... }
    fn all() -> Vec<Self> { vec![...] }
    fn allowed_roles(&self) -> &'static [&'static str] { ... }
}

pub struct AgentStateMachine { current_state: AgentState }

impl StateMachineBehavior for AgentStateMachine {
    type State = AgentState;
    type Transition = AgentTransition;
    fn current_state(&self) -> AgentState { self.current_state }
    fn set_current_state(&mut self, s: AgentState) { self.current_state = s; }
    fn can_transition(&self, t: AgentTransition) -> bool { /* unique table */ }
}

Enums§

StateMachineError
Shared error type for all state machines.

Traits§

StateMachineBehavior
Trait that provides all mechanical state machine methods as default impls.
TransitionMeta
Required trait for Transition enums — provides the metadata that StateMachineBehavior default methods need.