Struct pinned_init::needs_init::NeedsPinnedInit
source · [−]#[repr(transparent)]pub struct NeedsPinnedInit<'init, T: PinnedInit> { /* private fields */ }Expand description
A pointer to pinned data that needs to be initialized while pinned. When this pointer is neglected and not initialized, it will
- panic on drop (when debug assertions are enabled)
- produce a link time error (when debug assertions are disabled)
This is to prevent partial initialization and guarantee statically (when
used without debug assertions) that the type
Tis fully initialized and may be transmuted to its initialized form.
This pointer does not implement Deref or DerefMut, instead you
should only use NeedsPinnedInit::begin_init on this type to begin safe
initialization of the inner T.
Invariants and assumptions
- When the
'initlifetime expires, the value this pointer pointed to, will be initialized and have changed its type toT::Initialized. - From the construction of a [
NeedsPinnedInit<'init, T>] until the end of'initit assumes full control over the pointee. This means that no one else is allowed to access the underlying value.
Implementations
sourceimpl<'init, T: PinnedInit> NeedsPinnedInit<'init, T>
impl<'init, T: PinnedInit> NeedsPinnedInit<'init, T>
sourcepub unsafe fn new_unchecked(inner: Pin<&'init mut T>) -> Self
pub unsafe fn new_unchecked(inner: Pin<&'init mut T>) -> Self
Construct a new NeedsPinnedInit from the given Pin.
Safety
- When the
'initlifetime expires, the value atinnerwill be initialized and have changed type toT::Initialized. - From the moment this function is called until the end of
'initthe producedNeedsPinnedInitbecomes the only valid way to access the underlying value. - The caller needs to guarantee, that the pointer from which
innerwas derived changes its pointee type toT::Initialized, when'initends.
sourcepub fn begin_init(self) -> <T as BeginInit>::OngoingInit<'init>
pub fn begin_init(self) -> <T as BeginInit>::OngoingInit<'init>
Begin to initialize the value behind this NeedsPinnedInit.
sourcepub unsafe fn as_ptr(&self) -> *const T
pub unsafe fn as_ptr(&self) -> *const T
Get a raw const pointer to the value behind this NeedsPinnedInit.
Safety
The caller needs to carefully handle this pointer, because
- it is only valid for the duration that the underlying value T will live
for (also counting the lifetime of the value when it is
T::Initialized). - it is pinned.
- you may only generate a
*mut Tor&mut Tif the value ofTis wrapped in anUnsafeCell. - dereferencing the pointer outside of the initialization process of
T, while'inithas not expired, is illegal (this would violate an invariant ofNeedsPinnedInit). - this pointer needs to be aware, that the type of the value pointed to
will change from
TtoT::Initializedwhen'initexpires.
Storing this pointer inside of the T itself for example is sound.
sourcepub unsafe fn as_ptr_mut(&mut self) -> *mut T
pub unsafe fn as_ptr_mut(&mut self) -> *mut T
Get a raw mutable pointer to the value behind this NeedsPinnedInit.
Safety
The caller needs to carefully handle this pointer, because
- it is only valid for the duration that the underlying value T will live
for (also counting the lifetime of the value when it is
T::Initialized). - it is pinned.
- you may only call this function if the value of
Tis wrapped in anUnsafeCell. - dereferencing the pointer outside of the initialization process of
T, while'inithas not expired, is illegal (this would violate an invariant ofNeedsPinnedInit). - this pointer needs to be aware, that the type of the value pointed to
will change from
TtoT::Initializedwhen'initexpires.
Storing this pointer inside of the T itself for example is sound.
Trait Implementations
sourceimpl<'init, T: PinnedInit> Drop for NeedsPinnedInit<'init, T>
impl<'init, T: PinnedInit> Drop for NeedsPinnedInit<'init, T>
Auto Trait Implementations
impl<'init, T> RefUnwindSafe for NeedsPinnedInit<'init, T> where
T: RefUnwindSafe,
impl<'init, T> Send for NeedsPinnedInit<'init, T> where
T: Send,
impl<'init, T> Sync for NeedsPinnedInit<'init, T> where
T: Sync,
impl<'init, T> Unpin for NeedsPinnedInit<'init, T>
impl<'init, T> !UnwindSafe for NeedsPinnedInit<'init, T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more