use crate::{CustomWrapper, FinalizeProjection, Marker, Projectable, ProjectableMarker};
use atomic::Atomic;
use core::mem::transmute_copy;
unsafe impl<'a, T> CustomWrapper for &'a Atomic<T> {
type Output = Whatever<&'a Atomic<T>>;
}
#[repr(transparent)]
pub struct Whatever<T>(T);
unsafe impl<'a, T> Projectable for Whatever<&'a Atomic<T>> {
type Target = T;
type Marker = Marker<&'a Atomic<()>>;
fn get_raw(&self) -> (*mut Self::Target, Self::Marker) {
(self.0 as *const _ as *const T as _, Marker::new())
}
}
impl<'a, T: 'a> ProjectableMarker<T> for Marker<&'a Atomic<()>> {
type Output = &'a Atomic<T>;
unsafe fn from_raw(&self, raw: *mut T) -> Self::Output {
&*(raw as *mut Atomic<T>)
}
}
#[repr(transparent)]
pub struct NonAtomicWindow<T>(pub T);
impl<'a, T> FinalizeProjection for &&'a Atomic<NonAtomicWindow<T>> {
type Output = &'a T;
unsafe fn finalize(&self) -> Self::Output {
transmute_copy(*self)
}
}