use crate::states::traits::CreateAppState;
use crate::AppStateTrait;
use std::ops::Deref;
use std::sync::Arc;
pub struct AppState<T: ?Sized>(Arc<T>);
impl<T: 'static + Send> CreateAppState<T> for AppState<T> {
fn new(state: T) -> AppState<T> {
AppState(Arc::new(state))
}
}
impl<T: 'static + Send + Sync> AppStateTrait<T, AppState<T>> for AppState<T> {}
impl<T: ?Sized> AppState<T> {
pub fn get_ref(&self) -> &T {
&self.0
}
pub fn into_inner(self) -> Arc<T> {
self.0
}
}
impl<T: ?Sized> Deref for AppState<T> {
type Target = Arc<T>;
fn deref(&self) -> &Arc<T> {
&self.0
}
}
impl<T: ?Sized> Clone for AppState<T> {
fn clone(&self) -> AppState<T> {
AppState(Arc::clone(&self.0))
}
}
impl<T: ?Sized> From<Arc<T>> for AppState<T> {
fn from(arc: Arc<T>) -> Self {
AppState(arc)
}
}