konst::maybe_uninit

Function array_assume_init

Source
pub const unsafe fn array_assume_init<T, const N: usize>(
    md: [MaybeUninit<T>; N],
) -> [T; N]
Expand description

Const equivalent of MaybeUninit::array_assume_init

§Safety

This has the same safety requirements as MaybeUninit::array_assume_init

§Example

use std::mem::MaybeUninit;

use konst::maybe_uninit;

const INIT: [u16; 10] = {
    let mut arr: [MaybeUninit<u16>; 10] = maybe_uninit::UNINIT_ARRAY::V;

    let mut i = 0usize;
    while i < 10 {
        let x = (i as u16) + 1;
        arr[i as usize] = MaybeUninit::new(x * x);
        i += 1;
    }

    unsafe{ maybe_uninit::array_assume_init(arr) }
};

assert_eq!(INIT, [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]);