Function cl_traits::try_create_array [−][src]
pub fn try_create_array<E, F, T, const N: usize>(cb: F) -> Result<[T; N], E> where
F: FnMut(usize) -> Result<T, E>,
Expand description
Creates a fallible array [T; N] where each array element T is returned by the cb call.
- Example
use cl_traits::try_create_array; #[derive(Debug, PartialEq)] enum SomeError { Foo } let array: Result<[usize; 5], SomeError> = try_create_array(|i| Ok(i)); assert_eq!(array, Ok([0, 1, 2, 3, 4])); let another_array: Result<[usize; 5], SomeError> = try_create_array(|_| Err(SomeError::Foo)); assert_eq!(another_array, Err(SomeError::Foo));