6 releases (breaking)

0.6.0 Jan 3, 2024
0.5.0 Jul 29, 2023
0.4.0 May 7, 2023
0.3.0 Apr 19, 2023
0.1.0 Apr 7, 2023

#2411 in Rust patterns

25 downloads per month

Unlicense

22KB
345 lines

maybe_uninit_ext

crates.io docs.rs Dependency Status Pipeline Status Unlicense Minimum Supported Rust Version is 1.75

Extended maybe-uninit types.


lib.rs:

maybe_uninit_ext

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

Support for "extended" maybe-uninit types.

Examples

// 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]],
);

Nightly features

With the nightly feature flag enabled, many of the functions provided by this crate become const. Note that this is requires the nightly toolchain and depends on many unstable features. Use with caution.

Dependencies

~99KB