macro-machines
State machine macros with logging and graphviz dotfile generation
Current features
- Macros for creating state machines with and without
Debug
andDefault
:def_machine!
-- state machine implementingDefault
constructiondef_machine_debug!
-- state machine implementingDefault
construction and derivingDebug
def_machine_nodefault!
-- state machine requiring initialization argumentsdef_machine_nodefault_debug!
-- state machine requiring initialization arguments and derivingDebug
- Specified initial (required) and terminal (optional) states with (optional) initialization and termination actions
- States may have local state variables and state machines may have extended state variables
- Events with optional associated parameters and actions in which extended state
variables may be modified:
- External events -- transition from a specific source state to a specific target state
- Internal events -- an event that is additionally allowed to modify local state variables and leaves the current state unchanged
- Universal events -- transition from any source state to a specific target state
- Syntax allowing use of constrained type parameters in the types of extended state variables
- Logging using the
log
logging API - Graphviz DOT file generation of state machine transition diagrams
Current limitations
- Only trace-level messages are currently logged
Usage
Define and use a minimal state machine:
use def_machine_debug;
def_machine_debug!
Generate a dotfile and write to file:
use Write;
use MachineDotfile;
let mut f = create .unwrap;
f.write_all .unwrap;
drop ;
Rendered as PNG with $ dot -Tpng minimal.dot > minimal.png
:
For examples of more complex state machines, see the ./examples/
directory.