Trait Stateful

Source
pub trait Stateful<Q>
where Q: RawState,
{ type State: StateRepr<Item = Q>; // Required methods fn state(&self) -> &Self::State; fn state_mut(&mut self) -> &mut Self::State; // Provided methods fn set_state(&mut self, state: Self::State) -> &mut Self { ... } fn replace_state(&mut self, state: Self::State) -> Self::State { ... } fn swap_state(&mut self, state: &mut Self::State) { ... } fn take_state(&mut self) -> Self::State where Self::State: Default { ... } }
Expand description

Stateful is a trait establishing a common interface for all types that are state-aware.

Required Associated Types§

Source

type State: StateRepr<Item = Q>

Required Methods§

Source

fn state(&self) -> &Self::State

Source

fn state_mut(&mut self) -> &mut Self::State

Provided Methods§

Source

fn set_state(&mut self, state: Self::State) -> &mut Self

Source

fn replace_state(&mut self, state: Self::State) -> Self::State

replace the current state with the given value and return the old state.

Source

fn swap_state(&mut self, state: &mut Self::State)

swap the current state with another of the same type.

Source

fn take_state(&mut self) -> Self::State
where Self::State: Default,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§