[][src]Function array_tools::indexed_init_with

pub fn indexed_init_with<T, A, F>(initializer_fn: F) -> A where
    A: FixedSizeArray<T>,
    F: FnMut(usize) -> T, 

Creates a new array instance filled with values generated by a given function. This variant expects a function with single argument - an index of element to initialize.

Panics

  • Only panics if provided function does.

Examples

use array_tools;

let array: [u64; 7] = array_tools::indexed_init_with(|idx| {
    idx as u64 * 2
});

assert_eq!(array, [0, 2, 4, 6, 8, 10, 12]);