pub struct DynamicToolLifecycle { /* private fields */ }Expand description
Dynamic wrapper for runtime event dispatch.
This struct wraps the typestate machine and provides a handle() method
for dispatching events at runtime. Use this when events come from external
sources and can’t be determined at compile time.
Implementations§
Source§impl DynamicToolLifecycle
impl DynamicToolLifecycle
Sourcepub fn new(ctx: ToolLifecycleContext) -> Self
pub fn new(ctx: ToolLifecycleContext) -> Self
Create a new dynamic machine in the initial state.
Sourcepub fn handle(&mut self, event: ToolLifecycleEvent) -> Result<(), DynamicError>
pub fn handle(&mut self, event: ToolLifecycleEvent) -> Result<(), DynamicError>
Dispatch an event to the state machine at runtime.
Returns an error if:
- The event is not valid from the current state
- A guard callback fails
- An action callback fails
Sourcepub fn current_state(&self) -> &'static str
pub fn current_state(&self) -> &'static str
Get the name of the current state.
Source§impl DynamicToolLifecycle
impl DynamicToolLifecycle
Sourcepub fn into_enabled(self) -> Result<ToolLifecycle<Enabled>, Self>
pub fn into_enabled(self) -> Result<ToolLifecycle<Enabled>, Self>
Try to extract a typestate machine in the #state state.
Returns Ok if the machine is currently in this state,
otherwise returns Err(self) so you can try another state.
Sourcepub fn into_disabled(self) -> Result<ToolLifecycle<Disabled>, Self>
pub fn into_disabled(self) -> Result<ToolLifecycle<Disabled>, Self>
Try to extract a typestate machine in the #state state.
Returns Ok if the machine is currently in this state,
otherwise returns Err(self) so you can try another state.
Sourcepub fn into_defective(self) -> Result<ToolLifecycle<Defective>, Self>
pub fn into_defective(self) -> Result<ToolLifecycle<Defective>, Self>
Try to extract a typestate machine in the #state state.
Returns Ok if the machine is currently in this state,
otherwise returns Err(self) so you can try another state.