kernel::init

Function init_array_from_fn

Source
pub fn init_array_from_fn<I, const N: usize, T, E>(
    make_init: impl FnMut(usize) -> I,
) -> impl Init<[T; N], E>
where I: Init<T, E>,
Expand description

Initializes an array by initializing each element via the provided initializer.

§Examples

use kernel::{alloc::KBox, error::Error, init::init_array_from_fn};
let array: KBox<[usize; 1_000]> =
    KBox::init::<Error>(init_array_from_fn(|i| i), GFP_KERNEL).unwrap();
assert_eq!(array.len(), 1_000);