```rust use Machine; use StateMachine;
enum States { Empty, Move, Music, Last }
impl Machine
impl Machine
fn update(&self, state: &mut States) -> bool {
println!("Music state");
*state = States::Move;
true
}
}
impl Machine
fn on_exit(&self, _: &mut States) -> bool {
println!("On exit move state");
false
}
}
fn main() { let mut state = StateMachine::new(States::Empty); state.add(States::Music, Box::new(Music)); state.add(States::Empty, Box::new(Empty)); state.add(States::Move, Box::new(Move));
// Empty state
state.next();
// On enter music state
// Music state
//
// Stop state
// On exit move state
let _ = state.run();
} ```