-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
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 asOptiondoesn't implementstd::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>>, 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 most
If you have a preference (or a different suggestion), I should be able to cobble together a PR
Metadata
Metadata
Assignees
Labels
No labels