Struct stack_ptr::StackPtr
[−]
[src]
pub struct StackPtr<'a, T: 'a + ?Sized> { /* fields omitted */ }
An owning pointer to stack-allocated data. Similar to Box
, except Box
is heap-allocated.
Methods
impl<'a, T: 'a + ?Sized> StackPtr<'a, T>
[src]
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.
fn borrow(&self) -> &'a T
an implementation of std::borrow::Borrow, where the returned reference has the same lifetime as self
.
fn borrow_mut(&mut self) -> &'a mut T
an implementation of std::borrow::BorrowMut, where the returned reference has the same lifetime as self
.
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
.
unsafe fn from_raw_parts(
ptr: *mut T,
lifetime: PhantomData<&'a mut ()>
) -> StackPtr<'a, T>
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
.
Trait Implementations
impl<'a, T: ?Sized> Drop for StackPtr<'a, T>
[src]
impl<'a, T: ?Sized> Debug for StackPtr<'a, T> where
T: Debug,
[src]
T: Debug,
impl<'a, T: ?Sized> Deref for StackPtr<'a, T>
[src]
type Target = T
The resulting type after dereferencing
fn deref(&self) -> &T
The method called to dereference a value
impl<'a, T: ?Sized> DerefMut for StackPtr<'a, T>
[src]
fn deref_mut(&mut self) -> &mut T
The method called to mutably dereference a value