Struct StackPtr

Source
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>

Source

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.

Source

pub fn borrow(&self) -> &'a T

an implementation of std::borrow::Borrow, where the returned reference has the same lifetime as self.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'a, T> Debug for StackPtr<'a, T>
where T: Debug + ?Sized,

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T: ?Sized> Deref for StackPtr<'a, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<'a, T: ?Sized> DerefMut for StackPtr<'a, T>

Source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
Source§

impl<'a, T: ?Sized> Drop for StackPtr<'a, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, T: 'a + Send + ?Sized> Send for StackPtr<'a, T>

Source§

impl<'a, T: 'a + Sync + ?Sized> Sync for StackPtr<'a, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for StackPtr<'a, T>
where T: ?Sized,

§

impl<'a, T> RefUnwindSafe for StackPtr<'a, T>
where T: RefUnwindSafe + ?Sized,

§

impl<'a, T> Unpin for StackPtr<'a, T>
where T: Unpin + ?Sized,

§

impl<'a, T> !UnwindSafe for StackPtr<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.