use super::AtomicOptionRef;
use std::sync::Arc;
pub struct AtomicRef<T> {
inner: AtomicOptionRef<T>,
}
impl<T> AtomicRef<T> {
pub fn new() -> Self
where
T: Default,
{
Self::default()
}
pub fn from(value: impl Into<Arc<T>>) -> Self {
Self {
inner: AtomicOptionRef::from(value.into()),
}
}
pub fn load(&self) -> Arc<T> {
self.inner.load().unwrap()
}
pub fn store(&self, value: impl Into<Arc<T>>) {
self.inner.store(value.into())
}
pub fn swap(&self, value: impl Into<Arc<T>>) -> Arc<T> {
self.inner.swap(value.into()).unwrap()
}
}
impl<T> Default for AtomicRef<T>
where
T: Default,
{
fn default() -> Self {
Self::from(T::default())
}
}