use std::ops::Deref;
use std::sync::Arc;
pub struct Ref<T> {
pub(crate) inner: Box<Arc<T>>,
pub(crate) ptr: *const Arc<T>,
}
impl<T> Ref<T> {
pub fn as_ptr(&self) -> *const Arc<T> {
self.ptr
}
pub fn count(&self) -> usize {
Arc::strong_count(&*self.inner)
}
pub fn consume(self) -> Arc<T> {
*self.inner
}
}
impl<T: Copy> Ref<Option<T>> {
pub fn is_some(&self) -> bool {
self.inner.is_some()
}
}
impl<T: Copy> Ref<T> {
pub fn take_copy(&self) -> T {
**self.inner.as_ref()
}
}
impl<T: Clone> Ref<T> {
pub fn take_clone(&self) -> T {
let that = (**self.inner.as_ref()).clone();
that
}
}
#[cfg(feature = "raw-deref")]
impl<T> Deref for Ref<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&**self.inner
}
}
#[cfg(not(feature = "raw-deref"))]
impl<T> Deref for Ref<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&**self.inner
}
}