Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
FSMY
fsmy is a finite state machine rust library.
It is originally inspired by rust-fsm, with a few important differences, the main one being integrated support to contexts.
Features
- On-transition context mutation - when leaving a state, entering one and along the transition edge
- Custom alphabets for input, output, state and context
- Parent states (regions)
- DSL via
fsmy-dsl - Mermaid.js diagrams
- Final states detection
- Virtual states
- Ability to rewind states and context (see
JournaledStateMachine)
Planned features
- Function-based, non-static outputs
- Parallel states
- Other languages bindings
Usage
Add to your project
Use via DSL
The DSL is similar to the one in rust-fsm-dsl but also accepts
mutation closures to run on state transitions.
use state_machine;
/// Context is optional, if not provided defaults to the type `()`
state_machine!
use *;
let mut machine = default.start.unwrap;
let next = machine.consume;
assert!;
assert_eq!;
assert_eq!;
let next = machine.consume;
assert!;
assert!;
assert_eq!;
assert_eq!;
Context mutations
There are three different points where a context can be mutated, and all of them happen on a state transition and in the following order.
- The
on_leavemutation callback defined when defining a state viadefine_state, taken from the source state on the transition edge - The mutation defined when using
add_transition_with_mutation(can also be done via DSL, see example above) - The
on_entermutation callback defined when defining a state viadefine_state, taken from the target state on the transition edge
In other words, when transitioning from state A to state B:
on_leavefrom state A is called- Mutation on the edge is called
on_enteron state B is called
Currently on_enter and on_leave are not supported by the DSL and can only be registered through the regular state machine rust api.
Custom alphabet and trait bounds
When defining a custom alphabet it is important that especially state implements some traits needed by the state machine implementations. You can use whatever type you want but if you use enums, which is very common, you can just
to automatically implement all of these traits for you.
Parent states
You can define parent states for certain states. Parent states are automatically active if one of
their children is active, and therefore executes their on_enter and on_leave callbacks when appropriate.
This is supported partially by the DSL, allowing you to define parent states but no callbacks yet.
A parent-child relation can be defined like this using the DSL (when defining transitions):
...
Unloaded(LoadSong) => Loaded,
Loaded(Play) => Loaded.Playing,
Loaded.Playing(Pause) => Loaded.Paused,
Loaded.Stop => Unloaded
...
Virtual states
Cargo features
events: enables events busdsl: enables DSL macros (see below)history: enables the journaled version of the state machine implementation