[−][src]Crate statemachine_macro
Provides the statemachine!() macro.
Examples
use statemachine_macro::*; statemachine! { #[derive(Default)] pub struct Foo { pub allow_x: bool } enum FooState consumes [char, i32] from Start accepts [Done]; Start => { @enter => { println!("Entering Start!"); }, @leave => { println!("Leaving Start!"); }, @loop => { println!("Looping inside Start!"); }, char match 'a' => { println!("Got 'a'... Going to 'Done'!"); Done }, char match 'b' => { println!("Got 'b'... allowing 'x'!"); self.allow_x = true; Start }, char match 'x' => if self.allow_x { println!("Got authorized 'x'."); Done }, char match 'x' => if !self.allow_x { println!("Got unauthorized 'x'."); Error }, i32 match 42 => { println!("It is the answer!"); Error }, i32 match val => { println!("Got {}", val); Error }, _ => Error }, Error => { _ => Error }, Done => { _ => Error } } let mut foo: Foo = Default::default(); foo.consume('a'); assert!(foo.is_accepting()); assert!(!foo.allow_x); foo.reset(FooState::Start); foo.consume('b'); assert!(!foo.is_accepting()); assert!(foo.allow_x); foo.consume('x'); assert!(foo.is_accepting());
Macros
statemachine | Creates a state machine. |
statemachine_new | Creates a statemachine. |