pub unsafe trait PinInit<T: ?Sized, E = Infallible>: Sized {
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>;
}
Expand description
A pin-initializer for the type T
.
To use this initializer, you will need a suitable memory location that can hold a T
. This can
be Box<T>
, Arc<T>
, UniqueArc<T>
or even the stack (see stack_pin_init!
). Use the
InPlaceInit::pin_init
function of a smart pointer like Arc<T>
on this.
Also see the module description.
Safety
When implementing this type you will need to take great care. Also there are probably very few
cases where a manual implementation is necessary. Use pin_init_from_closure
where possible.
The PinInit::__pinned_init
function
- returns
Ok(())
if it initialized every field ofslot
, - returns
Err(err)
if it encountered an error and then cleanedslot
, this means:slot
can be deallocated without UB occurring,slot
does not need to be dropped,slot
is not partially initialized.
- while constructing the
T
atslot
it upholds the pinning invariants ofT
.