pub struct StateMachine<'a, C> {
pub memory: Arc<RwLock<Map<String, Value>>>,
pub context: Arc<RwLock<C>>,
/* private fields */
}Expand description
The state machine containing all states, the current state, memory, context, and handlers.
Fields§
§memory: Arc<RwLock<Map<String, Value>>>The memory used by the state machine to store data.
context: Arc<RwLock<C>>The context used by the state machine to store state.
Implementations§
Source§impl<C> StateMachine<'_, C>
impl<C> StateMachine<'_, C>
Sourcepub fn new<F>(
config_content: &str,
initial_state: Option<String>,
action_handler: F,
memory: Map<String, Value>,
context: C,
) -> Result<Self, String>
pub fn new<F>( config_content: &str, initial_state: Option<String>, action_handler: F, memory: Map<String, Value>, context: C, ) -> Result<Self, String>
Creates a new state machine from a JSON configuration string.
Sourcepub async fn trigger(&self, event: &str) -> Result<(), String>
pub async fn trigger(&self, event: &str) -> Result<(), String>
Triggers an event, causing a state transition if applicable and executing actions.
Sourcepub async fn get_current_state(&self) -> Result<String, String>
pub async fn get_current_state(&self) -> Result<String, String>
Returns the current state of the state machine.
Trait Implementations§
Auto Trait Implementations§
impl<'a, C> Freeze for StateMachine<'a, C>
impl<'a, C> !RefUnwindSafe for StateMachine<'a, C>
impl<'a, C> Send for StateMachine<'a, C>
impl<'a, C> Sync for StateMachine<'a, C>
impl<'a, C> Unpin for StateMachine<'a, C>
impl<'a, C> !UnwindSafe for StateMachine<'a, C>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.