Iterator::collect can collect an Iterator<Item = Result<T, E>> into a Result<Vec<T>, E>. It would be great if there was an array_init::from_iter equivalent to initialize a Result<[T;N], E> using such an iterator (maybe called try_from_iter).
Since from_iter is implemented on top of try_array_init_impl I think this shouldn't be too complex to realize. However, since an iterator that is too short can't produce an arbitrary error E, the return type may have to be
- a
Result<[T; N], Option<E>>; probably not good as Option doesn't implement std::error::Error
- a
Result<Option<[T; N]>, E>; needs a double unwrap if the iterator is too short, but probably a bit better
- a
Result<[T; N], ArrayInitError<E>>, where ArrayInitError<E> can either hold a length error or an E, and implements std::error::Error (if E implements it); this is probably the most complex to implement and increases the API surface the most
If you have a preference (or a different suggestion), I should be able to cobble together a PR
Iterator::collectcan collect anIterator<Item = Result<T, E>>into aResult<Vec<T>, E>. It would be great if there was anarray_init::from_iterequivalent to initialize aResult<[T;N], E>using such an iterator (maybe calledtry_from_iter).Since
from_iteris implemented on top oftry_array_init_implI think this shouldn't be too complex to realize. However, since an iterator that is too short can't produce an arbitrary errorE, the return type may have to beResult<[T; N], Option<E>>; probably not good asOptiondoesn't implementstd::error::ErrorResult<Option<[T; N]>, E>; needs a double unwrap if the iterator is too short, but probably a bit betterResult<[T; N], ArrayInitError<E>>, whereArrayInitError<E>can either hold a length error or anE, and implementsstd::error::Error(ifEimplements it); this is probably the most complex to implement and increases the API surface the mostIf you have a preference (or a different suggestion), I should be able to cobble together a PR