Expand description
Extended maybe-uninit types.
§Example
// Creates a 4x4 grid of `MaybeUninit` values.
let mut grid = maybe_uninit_ext::uninit::<[[MaybeUninit<usize>; 4]; 4]>();
grid.iter_mut().enumerate().for_each(|(i, row)| {
row.iter_mut().enumerate().for_each(|(j, tile)| {
tile.write(i * j);
});
});
// SAFETY: The grid was fully initialized.
let grid = unsafe { maybe_uninit_ext::assume_init(grid) };
assert_eq!(
grid,
[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6], [0, 3, 6, 9]],
);
§Minimum supported Rust version
The MSRV is currently 1.83.
This may change between minor versions.
§License
I release this crate into the public domain under the Unlicense.
Modules§
- assume_
init AssumeInit
: unsafely extract an initialized value from a value that may be uninitialized.- safe_
assume_ init SafeAssumeInit
: safely assume that uninitialized values are initialized, regardless of whether they actually are.- uninit
Uninit
: create uninitialized values.
Traits§
- Assume
Init - Types that may be in an uninitialized state.
- Safe
Assume Init - Types whose initialized state may be uninitialized, ensuring that they may always be assumed to be initialized.
- Uninit
- Types that may be constructed in an uninitialized state.
Functions§
- as_
mut_ ptr - Returns a mutable pointer to the initialized value.
- as_ptr
- Returns an immutable pointer to the initialized value.
- assume_
init ⚠ - Assumes the value is initialized.
- assume_
init_ ⚠drop - Assumes the value is initialized and drops it in place.
- assume_
init_ ⚠mut - Assumes the value is initialized. Returns a mutable reference.
- assume_
init_ ⚠read - Reads the value and assumes that it is initialized.
- assume_
init_ ⚠ref - Assumes the value is initialized. Returns a reference.
- new
- Creates an initialized instance of
T
. - safe_
assume_ init - Assumes that the value is initialized, regardless of whether it actually is.
- safe_
assume_ init_ mut - Assumes that the value is initialized, regardless of whether it actually is. Returns a mutable reference.
- safe_
assume_ init_ ref - Assumes that the value is initialized, regardless of whether it actually is. Returns a reference.
- uninit
- Creates an uninitialized instance of
T
. - write
- Initializes the value. Returns a mutable reference to the value after it has been initialized.
- zeroed
- Creates an uninitialized instance of
T
, filling it with0
bytes.