roopes_core/patterns/state/
simple.rs1use super::{
5 Context,
6 State,
7};
8
9#[allow(clippy::module_name_repetitions)]
14pub struct SimpleContext<S>
15where
16 S: State,
17{
18 state: S,
19}
20
21impl<S> SimpleContext<S>
22where
23 S: State,
24{
25 pub fn new(starting_state: S) -> SimpleContext<S>
28 {
29 Self {
30 state: starting_state,
31 }
32 }
33
34 pub fn get_state(&self) -> &S
36 {
37 &self.state
38 }
39}
40
41impl<S> Context<S> for SimpleContext<S>
42where
43 S: State,
44{
45 fn handle(&mut self)
46 {
47 self.state = self.state.execute();
48 }
49}