#[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, StaticUninit always 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 wrapping StaticUninits (this is achieved by the #[pinned_init] proc macro attribute).

Implementations

Creates an already initialized T with its init status statically tracked.

Retrieve the inner value of this StaticUninit.

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 T the caller needs to ensure that no other references exist.
  • &T the caller needs to ensure that no mutable references exist.

Creates a new uninitialized T with its init status statically tracked.

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.

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.

Initializes self using data and tracks that status statically.

Trait Implementations

Converts this type into a mutable reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Executes the destructor for this type. Read more

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.