Crate nekolib_doc::corro::array_removal

source ·
Expand description

Remove an element from the array.

§Examples

use std::mem::MaybeUninit;

use array_removal::array_remove;

fn uninit_array<T, const N: usize>() -> [MaybeUninit<T>; N] {
    unsafe { MaybeUninit::<[MaybeUninit<T>; N]>::uninit().assume_init() }
}

let mut array = uninit_array::<String, 10>();
array[0].write("A".to_owned());
array[1].write("B".to_owned());
array[2].write("C".to_owned());
array[3].write("X".to_owned());
array[4].write("D".to_owned());
array[5].write("E".to_owned());

unsafe {
    let elt = array_remove(&mut array, 3, 6);
    assert_eq!(elt, "X");

    let init = &*(&array[..5] as *const [_] as *const [String]);
    assert_eq!(init, ["A", "B", "C", "D", "E"]);

    for e in &mut array[..5] {
        e.assume_init_drop();
    }
}

Functions§