use crate::trace;
use core::marker::PhantomData;
use facet_core::{PtrMut, Shape};
use super::Peek;
pub struct OwnedPeek<'mem> {
pub(crate) data: PtrMut,
pub(crate) shape: &'static Shape,
pub(crate) _phantom: PhantomData<&'mem ()>,
}
impl<'mem, 'facet> OwnedPeek<'mem> {
pub const fn shape(&self) -> &'static Shape {
self.shape
}
pub fn as_peek(&'mem self) -> Peek<'mem, 'facet> {
unsafe { Peek::unchecked_new(self.data.as_const(), self.shape) }
}
}
impl<'mem> Drop for OwnedPeek<'mem> {
fn drop(&mut self) {
trace!("Dropping owned peek of shape '{}'", self.shape);
unsafe { self.shape.call_drop_in_place(self.data) };
let _ = unsafe { self.shape.deallocate_mut(self.data) };
}
}