Crate maybe_uninit_ext

Source
Expand description

crates.io Dependency Status Unlicense Minimum Supported Rust Version is 1.83

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§

AssumeInit
Types that may be in an uninitialized state.
SafeAssumeInit
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 with 0 bytes.