pub struct StepFsm { /* private fields */ }Expand description
Finite state machine for a workflow step.
§Transition table
| From | Event | To |
|---|---|---|
| Pending | Started | Running |
| Pending | Skipped | Skipped |
| Running | Succeeded | Completed |
| Running | Failed | Failed |
§Examples
use ironflow_engine::fsm::{StepFsm, StepEvent};
use ironflow_store::entities::StepStatus;
let mut fsm = StepFsm::new();
fsm.apply(StepEvent::Started).unwrap();
fsm.apply(StepEvent::Succeeded).unwrap();
assert_eq!(fsm.state(), StepStatus::Completed);Implementations§
Source§impl StepFsm
impl StepFsm
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new FSM in Pending state.
§Examples
use ironflow_engine::fsm::StepFsm;
use ironflow_store::entities::StepStatus;
let fsm = StepFsm::new();
assert_eq!(fsm.state(), StepStatus::Pending);Sourcepub fn from_state(state: StepStatus) -> Self
pub fn from_state(state: StepStatus) -> Self
Create a FSM from an existing state.
Sourcepub fn state(&self) -> StepStatus
pub fn state(&self) -> StepStatus
Returns the current state.
Sourcepub fn history(&self) -> &[Transition<StepStatus, StepEvent>]
pub fn history(&self) -> &[Transition<StepStatus, StepEvent>]
Returns the full transition history.
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Returns true if the FSM is in a terminal state.
Sourcepub fn apply(
&mut self,
event: StepEvent,
) -> Result<StepStatus, TransitionError<StepStatus, StepEvent>>
pub fn apply( &mut self, event: StepEvent, ) -> Result<StepStatus, TransitionError<StepStatus, StepEvent>>
Apply an event, transitioning to a new state if valid.
§Errors
Returns TransitionError if the event is not allowed in the current state.
§Examples
use ironflow_engine::fsm::{StepFsm, StepEvent};
let mut fsm = StepFsm::new();
assert!(fsm.apply(StepEvent::Started).is_ok());
assert!(fsm.apply(StepEvent::Started).is_err()); // can't start twiceTrait Implementations§
Auto Trait Implementations§
impl Freeze for StepFsm
impl RefUnwindSafe for StepFsm
impl Send for StepFsm
impl Sync for StepFsm
impl Unpin for StepFsm
impl UnsafeUnpin for StepFsm
impl UnwindSafe for StepFsm
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