1
- # Finny - Finite State Machines for Rust
1
+ ## Finny - Hierarchical Finite State Machines for Rust
2
2
3
+ [ ![ Crates.io] [ crates-badge ]] [ crates-url ]
4
+ [ ![ Documentation] ( https://docs.rs/finny/badge.svg )] ( https://docs.rs/finny )
3
5
![ Build] ( https://github.com/hashmismatch/finny.rs/workflows/Build/badge.svg )
4
6
5
- ## Features
7
+ ### Features
6
8
* Declarative, builder API with a procedural function macro that generate the dispatcher
7
9
* Compile-time transition graph validation
8
10
* No run-time allocations required, ` no_std ` support
9
11
* Support for generics within the shared context
10
12
* Transition guards and actions
11
- * FSM regions, also known as orthogonal states
13
+ * State regions, also known as orthogonal states
12
14
* Event queueing and run-to-completition execution
15
+ * Submachines, also known as Hierarchical State Machines
16
+ * Timers on states
13
17
14
- ## Example
18
+ ### Example
19
+
20
+ #### Cargo.toml
21
+
22
+ ``` toml
23
+ [dependencies ]
24
+ finny = " 0.2"
25
+ ```
26
+
27
+ #### Code
15
28
16
29
``` rust
17
- extern crate finny;
18
30
use finny :: {finny_fsm, FsmFactory , FsmResult , decl :: {BuiltFsm , FsmBuilder }};
19
31
20
32
// The context is shared between all guards, actions and transitions. Generics are supported here!
@@ -40,7 +52,7 @@ fn my_fsm(mut fsm: FsmBuilder<MyFsm, MyContext>) -> BuiltFsm {
40
52
})
41
53
. on_event :: <MyEvent >()
42
54
. transition_to :: <MyStateB >()
43
- . guard (| _ev , ctx | { ctx . context. val > 0 })
55
+ . guard (| _ev , ctx , _states | { ctx . context. val > 0 })
44
56
. action (| _ev , ctx , state_a , state_b | { ctx . context. val += 1 ; });
45
57
fsm . state :: <MyStateB >();
46
58
fsm . initial_state :: <MyStateA >();
@@ -60,5 +72,7 @@ fn main() -> FsmResult<()> {
60
72
Ok (())
61
73
}
62
74
```
75
+ [ crates-badge ] : https://img.shields.io/crates/v/finny.svg
76
+ [ crates-url ] : https://crates.io/crates/finny
63
77
64
- License: MIT OR Apache-2.0
78
+ License: MIT OR Apache-2.0
0 commit comments