Trait FromUnpinned

Source
pub unsafe trait FromUnpinned<Source>
where Self: Sized,
{ type PinData; // Required methods unsafe fn from_unpinned(src: Source) -> (Self, Self::PinData); unsafe fn on_pin(&mut self, pin_data: Self::PinData); }
Expand description

Trait to build StackPinned values from unpinned types.

Implementers of FromUnpinned<Source> indicate that they can be built from a Source instance, to the condition that they will be pinned afterwards.

§Safety

This trait both exposes unsafe functions and is unsafe to implement.

  • Unsafe functions are exposed because the functions have the preconditions of having to be called from the stack_let macro.
  • The trait itself is unsafe to implement because implementers must provide implementations of the functions that must uphold invariants that cannot be checked by the compiler. See the documentation of each function for information on the invariants.

Required Associated Types§

Source

type 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.

Required Methods§

Source

unsafe fn from_unpinned(src: Source) -> (Self, Self::PinData)

Performs a first initialization step, resulting in the creation of the Self instance.

§Safety
  • This function is used by the construction macro, it is never safe to call directly.
  • Implementers of this function are not allowed to consider that the type won’t ever move yet. (in particular, the Self instance is returned by this function). The type should be movable at this point.
Source

unsafe fn on_pin(&mut self, pin_data: Self::PinData)

Performs a second initialization step, resulting in the pinning of the Self instance.

§Safety
  • This function is used by the construction macro, it is never safe to call directly.
  • Implementers of this function are allowed to consider that the type won’t move ever again. You can for instance set autoborrows safely in this function.
  • For convenience, a naked mutable borrow is directly given. Implementers of this function are not allowed to move out of this mutable borrow.

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.

Implementors§

Source§

impl<U, T: FromUnpinned<U>> FromUnpinned<Unpinned<U, T>> for T