1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
/*
Appellation: traits <states>
Contrib: FL03 <jo3mccain@icloud.com>
*/
use core::borrow::Borrow;
pub trait StateKind {}
pub trait State<Q>
where
Q: StateKind,
{
type State: Borrow<Q>;
}
pub trait StateData {
type Item: ?Sized;
}
/// [Stateful] describes a stateful object
pub trait Stateful<Q>
where
Q: StateKind,
{
type State: State<Q>;
/// [Stateful::state] is used to get the state of the object
fn state(&self) -> &Self::State;
/// [Stateful::update_state] is used to update the state of the object
fn update_state(&mut self, state: Self::State);
}
/*
******** implementations ********
*/
impl<Q, S> State<Q> for S
where
Q: StateKind,
S: Borrow<Q>,
{
type State = S;
}