Expand description
§Qubit State Machine
A small, thread-safe finite state machine for Rust.
This crate provides a generic state machine (StateMachine) and a compact
fast state machine (FastStateMachine) built on compact usize codes and
FastCas.
§Examples
use qubit_state_machine::{AtomicRef, StateMachine};
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
enum State {
New,
Running,
Done,
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
enum Event {
Start,
Finish,
}
let machine = StateMachine::builder()
.add_states(&[State::New, State::Running, State::Done])
.initial_state(State::New)
.final_state(State::Done)
.transition(State::New, Event::Start, State::Running)
.transition(State::Running, Event::Finish, State::Done)
.build()
.expect("job state machine should be valid");
let state = AtomicRef::from_value(State::New);
assert_eq!(machine.trigger(&state, Event::Start).unwrap(), State::Running);
assert_eq!(*state.load(), State::Running);Structs§
- Atomic
Ref - Atomic reference type.
- Fast
State Machine - A compact, high-performance state machine backed by
FastCas. - Fast
State Machine Builder - Builder for dense, integer-coded state machine rules.
- State
Machine - Immutable finite state machine rules.
- State
Machine Builder - Builder used to define and validate finite state machine rules.
- Transition
- A directed transition in a finite state machine.
Enums§
- Fast
CasPolicy - Retry policy used by
crate::FastCaswhen compare-and-swap loses a race. - Fast
State Machine Build Error - Error returned when fast state machine configuration is invalid.
- Fast
State Machine Error - Error returned when applying an event through a
crate::FastStateMachine. - State
Machine Build Error - Error returned when state machine rules are internally inconsistent.
- State
Machine Error - Error returned when an event cannot be applied to the current state.
Constants§
- FAST_
STATE_ MACHINE_ DEFAULT_ CAS_ POLICY - Default retry policy used by
FastStateMachineBuilder.
Type Aliases§
- Fast
State Machine Result - Result returned by
FastStateMachineruntime transition APIs. - State
Machine Result - Result returned by event-triggering state machine operations.