ruex/foundation/patterns/fsm/
integrations.rs1use std::rc::Rc;
2
3use super::StateDef;
4
5pub trait FsmIntegration<T: FsmIntegration<T>>: Clone {
11 fn transition(&self, new_state: Rc<StateDef<T>>, old_state: Option<Rc<StateDef<T>>>) -> bool;
13}
14
15#[derive(Default, Debug, Clone)]
17pub struct CallbackIntegration;
18
19impl CallbackIntegration {
20 pub fn new() -> Self {
22 Self
23 }
24}
25
26impl FsmIntegration<Self> for CallbackIntegration {
27 fn transition(
28 &self,
29 new_state: Rc<StateDef<Self>>,
30 old_state: Option<Rc<StateDef<Self>>>,
31 ) -> bool {
32 if let Some(ref old_state) = old_state {
33 old_state.state.exit(self)
34 }
35
36 new_state.state.enter(self);
37
38 true
39 }
40}