MCPcopy Create free account
hub / github.com/Manishearth/array-init / try_array_init

Function try_array_init

src/lib.rs:185–190  ·  view source on GitHub ↗

Initialize an array given an initializer expression that may fail. The initializer is given the index (between 0 and `N - 1` included) of the element, and returns a `Result ,`. It is allowed to mutate external state; we will always initialize from lower to higher indices. # Examples ```rust # #![allow(unused)] # extern crate array_init; # #[derive(PartialEq,Eq,Debug)] struct DivideByZero

(initializer: F)

Source from the content-addressed store, hash-verified

183/// assert_eq!(res,Err(DivideByZero));
184/// ```
185pub fn try_array_init<Err, F, T, const N: usize>(initializer: F) -> Result<[T; N], Err>
186where
187 F: FnMut(usize) -> Result<T, Err>,
188{
189 try_array_init_impl::<Err, F, T, N, 1>(initializer)
190}
191
192#[inline]
193fn try_array_init_impl<Err, F, T, const N: usize, const D: i8>(

Callers 2

array_initFunction · 0.85
array_init_no_dropFunction · 0.85

Calls

no outgoing calls

Tested by 1

array_init_no_dropFunction · 0.68