Trait pinned_init::Init
source · [−]pub unsafe trait Init<T, E = Infallible>: PinInit<T, E> {
unsafe fn __init(self, slot: *mut T) -> Result<(), E>;
}Expand description
An initializer for T.
To use this initializer, you will need a suitable memory location that can hold a T. This can
be Box<T>, Arc<T>, or even the stack (see stack_init!). Use the
init function of a smart pointer like Box::init on this. Because PinInit<T, E> is a
super trait, you can use every function that takes it as well.
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 from_value and
init_from_closure where possible.
The Init::__init function
- returns
Ok(())iff it initialized every field of slot, - returns
Err(err)iff it encountered an error and then cleaned slot, this means:- slot can be deallocated without UB ocurring,
- slot does not need to be dropped,
- slot is not partially initialized.
The __pinned_init function from the supertrait PinInit needs to exectute the exact same
code as __init.
Contrary to its supertype PinInit<T, E> the caller is allowed to
move the pointee after initialization.