Struct StackPinned

Source
pub struct StackPinned<'pin, T>(/* private fields */);
Expand description

Struct that represents data that is pinned to the stack, at the point of declaration.

Because this property cannot be guaranteed by safe rust, constructing an instance of a StackPinned directly is unsafe. Rather, one should use the stack_let macro that returns a PinStack instance.

In particular, one should note the following about StackPinned instance:

  • It is impossible to safely pass a StackPinned instance to a function
  • It is impossible to safely return a StackPinned instance from a function
  • It is impossible to safely store a StackPinned instance inside of a struct

Instead, one should replace StackPinned<T> with PinStack<T> in each of these situations.

A PinStack<T> instance does have its benefits:

  • The underlying T instance is guaranteed to never move for T: !Unpin once pinned. This is useful for T types whose instances should never move.
  • For T: !Unpin, the destructor of T is guaranteed to run when the T leaves the stack frame it was allocated on, even if one uses std::mem::forget on the PinStack<T> instance.

Implementations§

Source§

impl<'pin, T> StackPinned<'pin, T>

Source

pub unsafe fn new(t: &'pin mut T) -> Self

§Safety

Currently the only way to build a safe StackPinned<T> instance is to use the stack_let macro that will return a PinStack<T> instance.

Trait Implementations§

Source§

impl<'pin, T> Deref for StackPinned<'pin, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'pin, T> DerefMut for StackPinned<'pin, T>

Source§

fn deref_mut(&mut self) -> &mut <Self as Deref>::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<'pin, T> Freeze for StackPinned<'pin, T>

§

impl<'pin, T> RefUnwindSafe for StackPinned<'pin, T>
where T: RefUnwindSafe,

§

impl<'pin, T> Send for StackPinned<'pin, T>
where T: Send,

§

impl<'pin, T> Sync for StackPinned<'pin, T>
where T: Sync,

§

impl<'pin, T> Unpin for StackPinned<'pin, T>

§

impl<'pin, T> !UnwindSafe for StackPinned<'pin, 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<U, T> FromUnpinned<Unpinned<U, T>> for T
where T: FromUnpinned<U>,

Source§

type PinData = <T as FromUnpinned<U>>::PinData

This associated type can be used to retain information between the creation of the instance and its pinning. This allows for some sort of “two-steps initialization” without having to store the initialization part in the type itself.
Source§

unsafe fn from_unpinned( src: Unpinned<U, T>, ) -> (T, <T as FromUnpinned<Unpinned<U, T>>>::PinData)

Performs a first initialization step, resulting in the creation of the Self instance. Read more
Source§

unsafe fn on_pin( &mut self, pin_data: <T as FromUnpinned<Unpinned<U, T>>>::PinData, )

Performs a second initialization step, resulting in the pinning of the Self instance. Read more
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.