use core::{convert::Infallible, fmt::Debug};
pub trait State: Debug + Send + Sync + 'static {
type Repr: Debug + Send + Sync + 'static;
fn into_repr(self) -> Self::Repr
where
Self: Sized;
fn from_repr(state: Self::Repr) -> Self
where
Self: Sized;
fn from_repr_ref(state: &Self::Repr) -> &Self
where
Self: Sized;
}
impl<T> State for T
where
T: Debug + Send + Sync + 'static,
{
type Repr = T;
fn into_repr(self) -> Self::Repr {
self
}
fn from_repr(this: Self::Repr) -> Self
where
Self: Sized,
{
this
}
fn from_repr_ref(this: &Self::Repr) -> &Self
where
Self: Sized,
{
this
}
}
#[derive(Debug)]
pub struct Stateless(#[allow(unused)] [()]);
impl State for Stateless {
type Repr = Infallible;
}