Skip to content

Feature Request: next_arrayvec iterator method #1024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wmstack opened this issue Apr 8, 2025 · 1 comment
Open

Feature Request: next_arrayvec iterator method #1024

wmstack opened this issue Apr 8, 2025 · 1 comment

Comments

@wmstack
Copy link

wmstack commented Apr 8, 2025

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.

@wmstack wmstack changed the title Add a next_arrayvec iterator method Feature Request: next_arrayvec iterator method Apr 8, 2025
@phimuemue
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants