pub fn initialize_from_option<T, F, const OUTPUT_SIZE: usize>(
f: F,
fill: T,
) -> ([T; OUTPUT_SIZE], usize)Expand description
Initialize a sized array from a closure taking the index and outputting an
Option of a element, stopping when the first
None is encountered.
Generates a new sized array generated from generator closure, which turns a index into a
Option<T> with T being elements of the generated array. If a
None value is found, the rest of the output array is filled with the fill value. Along
with the generated array, this utility returns at what index the given
None value was found
(OUTPUT_SIZE if not found).
§Examples
use array_utils::initialize_from_option;
assert_eq!(
initialize_from_option(|index| if index == 5 { None } else { Some(index) }, 42),
([0, 1, 2, 3, 4, 42, 42, 42], 5)
);§Panics
Only panics if the given f panics.