pub struct StackPtr<'a, T: 'a + ?Sized> { /* private fields */ }
Expand description
An owning pointer to stack-allocated data. Similar to Box
, except Box
is heap-allocated.
Implementations§
Source§impl<'a, T: 'a + ?Sized> StackPtr<'a, T>
impl<'a, T: 'a + ?Sized> StackPtr<'a, T>
Sourcepub unsafe fn new(ptr: *mut T, _lifetime: &'a mut ()) -> StackPtr<'a, T>
pub unsafe fn new(ptr: *mut T, _lifetime: &'a mut ()) -> StackPtr<'a, T>
ptr
must be a pointer to forgotten data on the stack, whose lifetime is at least as long as lifetime
’s lifetime. Better to just use the stack_ptr!
macro.
Sourcepub fn borrow(&self) -> &'a T
pub fn borrow(&self) -> &'a T
an implementation of std::borrow::Borrow, where the returned reference has the same lifetime as self
.
Sourcepub fn borrow_mut(&mut self) -> &'a mut T
pub fn borrow_mut(&mut self) -> &'a mut T
an implementation of std::borrow::BorrowMut, where the returned reference has the same lifetime as self
.
Sourcepub fn into_raw_parts(sp: StackPtr<'a, T>) -> (*mut T, PhantomData<&'a mut ()>)
pub fn into_raw_parts(sp: StackPtr<'a, T>) -> (*mut T, PhantomData<&'a mut ()>)
Consumes a StackPtr
without running its destructor, and returns a *mut
pointer to the data, and a std::marker::PhantomData
representing the lifetime of the StackPtr
. Useful for doing a conversion on the pointer and reconstructing a StackPtr
with from_raw_parts
.
Sourcepub unsafe fn from_raw_parts(
ptr: *mut T,
lifetime: PhantomData<&'a mut ()>,
) -> StackPtr<'a, T>
pub unsafe fn from_raw_parts( ptr: *mut T, lifetime: PhantomData<&'a mut ()>, ) -> StackPtr<'a, T>
Constructs a new StackPtr
from its raw parts. Usually called on the result of into_raw_parts
.