use std::{ops::Deref, sync::Arc};
use arc_swap::ArcSwap;
#[derive(Debug, Default)]
pub struct AtomicRef<T>(Arc<ArcSwap<T>>);
impl<T> AtomicRef<T> {
pub fn new(store: T) -> Self {
Self(Arc::new(ArcSwap::new(Arc::new(store))))
}
}
impl<T> From<Arc<T>> for AtomicRef<T> {
fn from(store: Arc<T>) -> Self {
Self(Arc::new(ArcSwap::new(store)))
}
}
impl<T> Deref for AtomicRef<T> {
type Target = ArcSwap<T>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> Clone for AtomicRef<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}