facet_reflect/peek/
owned.rs1use crate::trace;
2use core::marker::PhantomData;
3use facet_core::{PtrMut, Shape};
4
5use super::Peek;
6
7pub struct OwnedPeek<'mem> {
12 pub(crate) data: PtrMut,
13 pub(crate) shape: &'static Shape,
14 pub(crate) _phantom: PhantomData<&'mem ()>,
15}
16
17impl<'mem, 'facet> OwnedPeek<'mem> {
18 pub fn shape(&self) -> &'static Shape {
20 self.shape
21 }
22
23 pub fn as_peek(&'mem self) -> Peek<'mem, 'facet> {
25 unsafe { Peek::unchecked_new(self.data.as_const(), self.shape) }
26 }
27}
28
29impl<'mem> Drop for OwnedPeek<'mem> {
30 fn drop(&mut self) {
31 trace!("Dropping owned peek of shape '{}'", self.shape);
32 unsafe { self.shape.call_drop_in_place(self.data) };
33 let _ = unsafe { self.shape.deallocate_mut(self.data) };
34 }
35}