use core::ops::{Deref, DerefMut};
pub struct WeakPointer<T>(*mut T);
impl<T> WeakPointer<T> {
pub unsafe fn new(ptr: *const T) -> Self {
Self(ptr as _)
}
pub unsafe fn null() -> Self {
Self(0 as _)
}
pub fn is_null(&self) -> bool {
self.0.is_null()
}
}
impl<T> Deref for WeakPointer<T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &(*self.0) }
}
}
impl<T> DerefMut for WeakPointer<T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut (*self.0) }
}
}
unsafe impl<T> Send for WeakPointer<T> {}
unsafe impl<T> Sync for WeakPointer<T> {}