[−][src]Crate statemachine_macro
Provides the statemachine!() macro.
Examples
use statemachine_macro::*; statemachine! { pub struct Foo { 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 } }
Macros
statemachine |