facet_reflect/poke/
pointer.rs1use facet_core::PointerDef;
2
3use super::Poke;
4
5pub struct PokePointer<'mem, 'facet> {
13 pub(crate) value: Poke<'mem, 'facet>,
14 pub(crate) def: PointerDef,
15}
16
17impl<'mem, 'facet> core::fmt::Debug for PokePointer<'mem, 'facet> {
18 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
19 f.debug_struct("PokePointer").finish_non_exhaustive()
20 }
21}
22
23impl<'mem, 'facet> PokePointer<'mem, 'facet> {
24 #[must_use]
26 #[inline]
27 pub const fn def(&self) -> &PointerDef {
28 &self.def
29 }
30
31 #[inline]
35 pub fn borrow_inner(&self) -> Option<crate::Peek<'_, 'facet>> {
36 let borrow_fn = self.def.vtable.borrow_fn?;
37 let pointee_shape = self.def.pointee()?;
38 let inner_ptr = unsafe { borrow_fn(self.value.data()) };
39 Some(unsafe { crate::Peek::unchecked_new(inner_ptr, pointee_shape) })
40 }
41
42 #[inline]
44 pub const fn into_inner(self) -> Poke<'mem, 'facet> {
45 self.value
46 }
47
48 #[inline]
50 pub fn as_peek_pointer(&self) -> crate::PeekPointer<'_, 'facet> {
51 crate::PeekPointer {
52 value: self.value.as_peek(),
53 def: self.def,
54 }
55 }
56}