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
StackPinnedinstance to a function - It is impossible to safely return a
StackPinnedinstance from a function - It is impossible to safely store a
StackPinnedinstance 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
Tinstance is guaranteed to never move forT: !Unpinonce pinned. This is useful forTtypes whose instances should never move. - For
T: !Unpin, the destructor ofTis guaranteed to run when the T leaves the stack frame it was allocated on, even if one usesstd::mem::forgeton thePinStack<T>instance.
Implementations§
Source§impl<'pin, T> StackPinned<'pin, T>
impl<'pin, T> StackPinned<'pin, T>
Sourcepub unsafe fn new(t: &'pin mut T) -> Self
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>
impl<'pin, T> Deref for StackPinned<'pin, T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<U, T> FromUnpinned<Unpinned<U, T>> for Twhere
T: FromUnpinned<U>,
impl<U, T> FromUnpinned<Unpinned<U, T>> for Twhere
T: FromUnpinned<U>,
Source§type PinData = <T as FromUnpinned<U>>::PinData
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)
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