itertools
itertools copied to clipboard
Feature Request: `next_arrayvec` iterator method
It would be interesting to add a next_arrayvec<N> iterator method. It should construct an ArrayVec with capacity N, filling it from the next elements of an iterator. If not enough elements are there to fill it to its capacity, the ArrayVec would retain the remainder of the elements of the iterator instead of error-ing.
This seems more ergonomic to work with than next_array which returns Option<[T;N]> without the ability to access the dropped elements or the standard library's unstable next_chunk which returns Result<[T; N], IntoIter<T>>, where the error is an iterator over the rest of the elements.
It could also be clean API to add a collect_arrayvec which requires an iterator to have at most N elements but potentially less, whereas next_arrayvec<N> makes no requirements on the iterator.
So far we refrained from bringing in arrayvec as a dependency, but @jswrenn I sincerely ask myself if next_arrayvec would actually the superior API. Intuitively, I lean towards "yes": It seems more general, callers can still get their array by using into_inner, and there are no items cut off.