use super::{RawState, StateRepr};
pub trait Stateful<Q>
where
Q: RawState,
{
type State: StateRepr<Item = Q>;
fn state(&self) -> &Self::State;
fn state_mut(&mut self) -> &mut Self::State;
fn set_state(&mut self, state: Self::State) -> &mut Self {
*self.state_mut() = state;
self
}
fn replace_state(&mut self, state: Self::State) -> Self::State {
core::mem::replace(self.state_mut(), state)
}
fn swap_state(&mut self, state: &mut Self::State) {
core::mem::swap(self.state_mut(), state)
}
fn take_state(&mut self) -> Self::State
where
Self::State: Default,
{
core::mem::take(self.state_mut())
}
}