pub fn array_init<F, T, const N: usize>(initializer: F) -> [T; N]
Expand description
Initialize an array given an initializer expression.
The initializer is given the index of the element. It is allowed to mutate external state; we will always initialize the elements in order.
ยงExamples
// Initialize an array of length 50 containing
// successive squares
let arr: [usize; 50] = array_init::array_init(|i| i * i);
assert!(arr.iter().enumerate().all(|(i, &x)| x == i * i));