use std::fmt;
use std::ops;
use std::sync::Arc;
pub struct State<T>(Arc<T>);
impl<T> State<T> {
pub fn new(state: T) -> State<T> {
State(Arc::new(state))
}
pub fn get_ref(&self) -> &T {
self.0.as_ref()
}
pub fn into_inner(self) -> Arc<T> {
self.0
}
}
impl<T> ops::Deref for State<T> {
type Target = Arc<T>;
fn deref(&self) -> &Arc<T> {
&self.0
}
}
impl<T> Clone for State<T> {
fn clone(&self) -> State<T> {
State(self.0.clone())
}
}
impl<T> From<Arc<T>> for State<T> {
fn from(arc: Arc<T>) -> Self {
State(arc)
}
}
impl<T> fmt::Debug for State<T>
where
T: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "State: {:?}", self.0)
}
}
impl<T> fmt::Display for State<T>
where
T: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
}
}