Function array_utils::initialize_from_result [−][src]
pub fn initialize_from_result<T, F, E, const OUTPUT_SIZE: usize>(
f: F,
fill: T
) -> ([T; OUTPUT_SIZE], usize) where
T: Copy,
F: Fn(usize) -> Result<T, E>,
Initialize a sized array from a closure taking the index and outputting an
Result
of a element, stopping when the first
Err
is encountered.
Generates a new sized array generated from generator closure, which turns a index into a
Result<T, E>
with T
being elements of the generated array. If a
Err
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
Err
value was found
(OUTPUT_SIZE
if not found).
Examples
use array_utils::initialize_from_result; assert_eq!( initialize_from_result(|index| if index == 5 { Err(()) } else { Ok(index) }, 42), ([0, 1, 2, 3, 4, 42, 42, 42], 5) );
Panics
Only panics if the given f
panics.