A code generator for finite state machines with the following features:
- An
entryapi to transition the state machine. - Illegal states and transitions are unrepresentable.
- States can contain data.
- Custom
#[derive(..)]support. #![no_std]support.- Inline SVG diagrams of the state machine in docs.
// define the machine.
// you can also use the DOT language if you prefer.
dsl!
use ;
// instantiate the machine
let mut machine = new;
loop
Features
macros(default): Include the [dot] and [dsl] macros.svg(default): The macros will shell out todot, if available, and generate a diagram of the state machine for documentation.std(default): Includes the [FSMGenerator], for custom codegen tools.cli: This does not affect the library, but if you
You will get ancargo install fsmentry --features=clifsmentrybinary that you can use to generate code.
Here are more details about the generated code.
dsl!
use ;
// ^ A module with matching publicity is generated for the state machine.
// The `#[derive(..)]`s apply to the `State` and the `MyStateMachine` items.
let mut machine = arbitrary;
// you can also inspect and mutate the state yourself.
let state: &State = machine.state;
let state: &mut State = machine.state_mut;
match machine.entry