[−][src]Function array_init::array_init
pub fn array_init<Array, F>(initializer: F) -> Array where
Array: IsArray,
F: FnMut(usize) -> Array::Item,
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));