pub struct StateMachine {
pub resource_type: String,
pub states: Vec<String>,
pub initial_state: String,
pub transitions: Vec<StateTransition>,
pub sub_scenarios: Vec<SubScenario>,
pub visual_layout: Option<VisualLayout>,
pub metadata: HashMap<String, Value>,
}Expand description
State machine for resource lifecycle management
Fields§
§resource_type: StringResource type this state machine applies to
states: Vec<String>All possible states
initial_state: StringInitial state for new resources
transitions: Vec<StateTransition>Allowed transitions between states
sub_scenarios: Vec<SubScenario>Nested sub-scenarios that can be referenced from this state machine
visual_layout: Option<VisualLayout>Visual layout information for the editor (node positions, edges, etc.)
metadata: HashMap<String, Value>Additional metadata for editor-specific data
Implementations§
Source§impl StateMachine
impl StateMachine
Sourcepub fn new(
resource_type: impl Into<String>,
states: Vec<String>,
initial_state: impl Into<String>,
) -> Self
pub fn new( resource_type: impl Into<String>, states: Vec<String>, initial_state: impl Into<String>, ) -> Self
Create a new state machine
Sourcepub fn add_transition(self, transition: StateTransition) -> Self
pub fn add_transition(self, transition: StateTransition) -> Self
Add a transition
Sourcepub fn add_transitions(self, transitions: Vec<StateTransition>) -> Self
pub fn add_transitions(self, transitions: Vec<StateTransition>) -> Self
Add multiple transitions
Sourcepub fn can_transition(&self, from: &str, to: &str) -> bool
pub fn can_transition(&self, from: &str, to: &str) -> bool
Check if a transition is allowed
Sourcepub fn next_states(&self, current: &str) -> Vec<String>
pub fn next_states(&self, current: &str) -> Vec<String>
Get next possible states from current state
Sourcepub fn select_next_state(&self, current: &str) -> Option<String>
pub fn select_next_state(&self, current: &str) -> Option<String>
Select next state based on probabilities
Sourcepub fn add_sub_scenario(self, sub_scenario: SubScenario) -> Self
pub fn add_sub_scenario(self, sub_scenario: SubScenario) -> Self
Add a sub-scenario
Sourcepub fn with_visual_layout(self, layout: VisualLayout) -> Self
pub fn with_visual_layout(self, layout: VisualLayout) -> Self
Set visual layout
Sourcepub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
pub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
Set metadata value
Sourcepub fn get_sub_scenario(&self, id: &str) -> Option<&SubScenario>
pub fn get_sub_scenario(&self, id: &str) -> Option<&SubScenario>
Get a sub-scenario by ID
Sourcepub fn get_sub_scenario_mut(&mut self, id: &str) -> Option<&mut SubScenario>
pub fn get_sub_scenario_mut(&mut self, id: &str) -> Option<&mut SubScenario>
Get a sub-scenario by ID mutably
Trait Implementations§
Source§impl Clone for StateMachine
impl Clone for StateMachine
Source§fn clone(&self) -> StateMachine
fn clone(&self) -> StateMachine
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for StateMachine
impl RefUnwindSafe for StateMachine
impl Send for StateMachine
impl Sync for StateMachine
impl Unpin for StateMachine
impl UnsafeUnpin for StateMachine
impl UnwindSafe for StateMachine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more