use crate::{assume_accessed, BorrowPessimize, Pessimize, PessimizeCast};
use core::{
ops::{Deref, DerefMut},
pin::Pin,
};
unsafe impl<T: ?Sized + Unpin, P: Deref<Target = T> + Pessimize> PessimizeCast for Pin<P> {
type Pessimized = P;
#[inline]
fn into_pessimize(self) -> P {
Self::into_inner(self)
}
#[inline]
unsafe fn from_pessimize(p: P) -> Self {
Self::new(p)
}
}
impl<T: ?Sized + Unpin, P: Deref<Target = T> + DerefMut + Pessimize> BorrowPessimize for Pin<P>
where
*const T: Pessimize,
{
type BorrowedPessimize = *const T;
#[inline]
fn with_pessimize(&self, f: impl FnOnce(&Self::BorrowedPessimize)) {
f(&(self.deref() as *const T))
}
#[inline]
fn assume_accessed_impl(&mut self) {
assume_accessed(&mut (self.deref_mut() as *const T))
}
}