scsys_core/state/traits/
stateful.rs1use super::{RawState, StateRepr};
6
7pub trait Stateful<Q>
9where
10 Q: RawState,
11{
12 type State: StateRepr<Item = Q>;
13
14 fn state(&self) -> &Self::State;
15
16 fn state_mut(&mut self) -> &mut Self::State;
17
18 fn set_state(&mut self, state: Self::State) -> &mut Self {
19 *self.state_mut() = state;
20 self
21 }
22 fn replace_state(&mut self, state: Self::State) -> Self::State {
25 core::mem::replace(self.state_mut(), state)
26 }
27 fn swap_state(&mut self, state: &mut Self::State) {
29 core::mem::swap(self.state_mut(), state)
30 }
31
32 fn take_state(&mut self) -> Self::State
33 where
34 Self::State: Default,
35 {
36 core::mem::take(self.state_mut())
37 }
38}