pub struct StateMachine {
pub name: String,
pub display_name: Option<String>,
pub description: Option<String>,
pub initial_state: String,
pub states: Vec<StateDef>,
pub transitions: Vec<Transition>,
}Expand description
A state machine schema describing lifecycle states and transitions.
Schema-only: defines structure but does not execute transitions. Guards and side effects are string references resolved externally.
use ferro_projections::{StateMachine, StateDef, Transition};
let machine = StateMachine::new("order_lifecycle")
.initial("draft")
.state(StateDef::new("draft").display_name("Draft"))
.state(StateDef::new("completed").display_name("Completed").final_state())
.transition(Transition::new("draft", "complete", "completed"));
let warnings = machine.validate().unwrap();
assert!(warnings.is_empty());Fields§
§name: StringMachine identifier (e.g., “order_lifecycle”).
display_name: Option<String>Human-readable name.
description: Option<String>Description of what this state machine models.
initial_state: StringName of the initial state (must exist in states).
states: Vec<StateDef>State definitions.
transitions: Vec<Transition>Transition definitions.
Implementations§
Source§impl StateMachine
impl StateMachine
Sourcepub fn display_name(self, name: impl Into<String>) -> Self
pub fn display_name(self, name: impl Into<String>) -> Self
Sets the human-readable display name.
Sourcepub fn description(self, desc: impl Into<String>) -> Self
pub fn description(self, desc: impl Into<String>) -> Self
Sets the description.
Sourcepub fn transition(self, transition: Transition) -> Self
pub fn transition(self, transition: Transition) -> Self
Adds a transition definition.
Sourcepub fn validate(&self) -> Result<Vec<Warning>, Error>
pub fn validate(&self) -> Result<Vec<Warning>, Error>
Validates structural integrity and returns warnings for potential issues.
Returns Err for fatal issues (missing initial state, invalid references).
Returns Ok(warnings) for structural concerns (unreachable states, dead-ends).
Sourcepub fn states_for_event(&self, event: &str) -> Vec<&Transition>
pub fn states_for_event(&self, event: &str) -> Vec<&Transition>
Returns all transitions triggered by a given event.
Sourcepub fn events_from_state(&self, state: &str) -> Vec<&Transition>
pub fn events_from_state(&self, state: &str) -> Vec<&Transition>
Returns outgoing transitions from a state.
Trait Implementations§
Source§impl Clone for StateMachine
impl Clone for StateMachine
Source§fn clone(&self) -> StateMachine
fn clone(&self) -> StateMachine
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StateMachine
impl Debug for StateMachine
Source§impl<'de> Deserialize<'de> for StateMachine
impl<'de> Deserialize<'de> for StateMachine
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for StateMachine
impl JsonSchema for StateMachine
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more