Struct pinned_init::static_uninit::StaticUninit
source · [−]#[repr(transparent)]pub struct StaticUninit<T, const INIT: bool> { /* private fields */ }Expand description
This type is similar to MaybeUninit, but it provides a safe interface
for initialization which can then be used statically.
It represents a Value which is
- uninitialized iff INIT == false
- initialized iff INIT == true
StaticUninit<T, true> behaves like T, as it implements [DerefMut<Target = T>],
BorrowMut<T> and more, you can also take the value directly with StaticUninit::into_inner.
It also gives access to an unsafe interface allowing arbitrary modifications
of the underlying MaybeUninit if there are more complex initialization
requirements.
Safety
If at any point you use one of the unsafe methods to access and modify the
inner MaybeUninit<T>, you need to keep track of the initialization state
of that particular StaticUninit until you pass it to some other part of
the code. It is unsound to release a StaticUninit in
- a partially initialized state
- an unknown state of initialization
to other code,
StaticUninitalways is either fully initialized, or fully uninitialized. To achive partial initialization, use smaller components that can be fully initialized seperatly and then create a wrapper struct using multiple wrappingStaticUninits (this is achieved by the#[pinned_init]proc macro attribute).
Implementations
sourceimpl<T> StaticUninit<T, true>
impl<T> StaticUninit<T, true>
sourcepub fn new(data: T) -> Self
pub fn new(data: T) -> Self
Creates an already initialized T with its init status statically
tracked.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Retrieve the inner value of this StaticUninit.
sourcepub unsafe fn raw_get(this: *mut Self) -> *mut T
pub unsafe fn raw_get(this: *mut Self) -> *mut T
Gets a mutable pointer to the initialized value. This avoids creating a reference, allowing
mutable aliasing using *mut. This function is inspired by
raw_get from UnsafeCell.
Safety
The supplied pointer must be valid.
When casting the returned pointer to
&mut Tthe caller needs to ensure that no other references exist.&Tthe caller needs to ensure that no mutable references exist.
sourceimpl<T> StaticUninit<T, false>
impl<T> StaticUninit<T, false>
sourcepub unsafe fn as_uninit_ref(&self) -> &MaybeUninit<T>
pub unsafe fn as_uninit_ref(&self) -> &MaybeUninit<T>
Gives access to the inner MaybeUninit immutably.
Safety
You need to keep track of the initialization state of self, it is
unsound to leave a StaticUninit in
- a partially initialized state
- an unknown state of initialization and allow code to observe it unknowingly.
sourcepub unsafe fn as_uninit_mut(&mut self) -> &mut MaybeUninit<T>
pub unsafe fn as_uninit_mut(&mut self) -> &mut MaybeUninit<T>
Gives access to the inner MaybeUninit mutably.
Safety
You need to keep track of the initialization state of self, it is
unsound to leave a StaticUninit in
- a partially initialized state
- an unknown state of initialization and allow code to observe it unknowingly.
sourcepub fn write(self, data: T) -> StaticUninit<T, true>
pub fn write(self, data: T) -> StaticUninit<T, true>
Initializes self using data and tracks that status statically.
Trait Implementations
sourceimpl<T> AsMut<T> for StaticUninit<T, true>
impl<T> AsMut<T> for StaticUninit<T, true>
sourceimpl<T> AsRef<T> for StaticUninit<T, true>
impl<T> AsRef<T> for StaticUninit<T, true>
sourceimpl<T> Borrow<T> for StaticUninit<T, true>
impl<T> Borrow<T> for StaticUninit<T, true>
sourceimpl<T> BorrowMut<T> for StaticUninit<T, true>
impl<T> BorrowMut<T> for StaticUninit<T, true>
sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T: Clone> Clone for StaticUninit<T, true>
impl<T: Clone> Clone for StaticUninit<T, true>
sourceimpl<T> Deref for StaticUninit<T, true>
impl<T> Deref for StaticUninit<T, true>
sourceimpl<T> DerefMut for StaticUninit<T, true>
impl<T> DerefMut for StaticUninit<T, true>
sourceimpl<T, const INIT: bool> Drop for StaticUninit<T, INIT>
impl<T, const INIT: bool> Drop for StaticUninit<T, INIT>
sourceimpl<T> From<T> for StaticUninit<T, true>
impl<T> From<T> for StaticUninit<T, true>
sourceimpl<T: Hash> Hash for StaticUninit<T, true>
impl<T: Hash> Hash for StaticUninit<T, true>
sourceimpl<T: PartialEq<U>, U> PartialEq<StaticUninit<U, true>> for StaticUninit<T, true>
impl<T: PartialEq<U>, U> PartialEq<StaticUninit<U, true>> for StaticUninit<T, true>
sourcefn eq(&self, other: &StaticUninit<U, true>) -> bool
fn eq(&self, other: &StaticUninit<U, true>) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &StaticUninit<U, true>) -> bool
fn ne(&self, other: &StaticUninit<U, true>) -> bool
This method tests for !=.
sourceimpl<T: PartialOrd<U>, U> PartialOrd<StaticUninit<U, true>> for StaticUninit<T, true>
impl<T: PartialOrd<U>, U> PartialOrd<StaticUninit<U, true>> for StaticUninit<T, true>
sourcefn partial_cmp(&self, other: &StaticUninit<U, true>) -> Option<Ordering>
fn partial_cmp(&self, other: &StaticUninit<U, true>) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
sourcefn lt(&self, other: &StaticUninit<U, true>) -> bool
fn lt(&self, other: &StaticUninit<U, true>) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
sourcefn gt(&self, other: &StaticUninit<U, true>) -> bool
fn gt(&self, other: &StaticUninit<U, true>) -> bool
This method tests greater than (for self and other) and is used by the > operator. Read more
sourcefn le(&self, other: &StaticUninit<U, true>) -> bool
fn le(&self, other: &StaticUninit<U, true>) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
sourcefn ge(&self, other: &StaticUninit<U, true>) -> bool
fn ge(&self, other: &StaticUninit<U, true>) -> bool
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
impl<T: Eq> Eq for StaticUninit<T, true>
Auto Trait Implementations
impl<T, const INIT: bool> RefUnwindSafe for StaticUninit<T, INIT> where
T: RefUnwindSafe,
impl<T, const INIT: bool> Send for StaticUninit<T, INIT> where
T: Send,
impl<T, const INIT: bool> Sync for StaticUninit<T, INIT> where
T: Sync,
impl<T, const INIT: bool> Unpin for StaticUninit<T, INIT> where
T: Unpin,
impl<T, const INIT: bool> UnwindSafe for StaticUninit<T, INIT> where
T: UnwindSafe,
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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more