Trait PointerPinUnforgotten

Source
pub unsafe trait PointerPinUnforgotten: PointerLike + PointerDeref { }
Expand description

Trait that allows to create pinned mutable references to the pointed-at object, when assuming that the original smart-pointer won’t leak.

Such specific definition of this trait is needed to ensure pin’s drop guarantee in the context of extending lifetimes. If something is unclear, so please refer to implementations and their documentation. Specifically RefOnce impl might give you enough insight.

§Safety

Implementer must guarantee safety of creating, using and keeping of pinned mutable reference from the raw pointer returned by PointerLike::into_ptr, if the original smart-pointer won’t leak. It must also be allowed to operate on this raw pointer in the manner of a pinned mutable reference.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<Ptr: PointerDerefMut> PointerPinUnforgotten for Pin<Ptr>

We are already pinned, so this is fine

Source§

impl<T> PointerPinUnforgotten for Box<T>

Safe because of Box::into_pin

Source§

impl<T: Unpin> PointerPinUnforgotten for &mut T

Same as PointerDerefMut implementation because of Unpin

Implementors§

Source§

impl<T> PointerPinUnforgotten for RefOnce<'_, T>

Note that RefOnce::into_pin implementation, mimicking the Box::into_pin would be unsound because RefOnce stores object within the std::mem::MaybeUninit slot allocated somewhere (including on a stack) which would allow us to deallocate pinned object without first calling drop on it, thus violating the pin’s drop guarantee. However we can safely assume that this pointer won’t be forgotten and drop will “eventually” run, so we are safe here.