Function brownstone::build_with[][src]

pub fn build_with<T, F, const N: usize>(next_value: F) -> [T; N] where
    F: for<'a> FnMut(&'a mut [T]) -> T, 
Expand description

Build a fixed-size array with an initializer function. The initializer is called once for each item in the length of the array, and the completed array is returned.

Each time the method is called, it is provided with context in the form of the prefix of the array that has already been initialized.

Example

let fib: [i32; 10] = brownstone::build_with(|prefix| match *prefix {
    [] => 0,
    [_] => 1,
    [.., a, b] => a + b,
});

assert_eq!(fib, [0, 1, 1, 2, 3, 5, 8, 13, 21, 34])