-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Selfexhausting iter adapter #2370
RFC: Selfexhausting iter adapter #2370
Conversation
# Implementation | ||
|
||
The `exhausting()` method should take the iterator by value. | ||
During iteration, `Exhausting` is a trivial wrapper that acts like `&mut Self`, meaning it implements all the Iterator traits that the contained iter implements and will always do external iteration. On drop, it runs `for _ in self {}`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why always external iteration? What would keep it from doing internal iteration with try_fold
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I was confused about internal iteration and the requirement for consumption.
try_fold makes it possible to use internal iteration
Note that the flag workaround you propose in the drawbacks section is basically a reimplementation of |
Thank you for writing this RFC! The libs team discussed this today, and we felt that this seems too niche of a functionality and that the motivation seemed too weak, especially with the accompanying non-exhausting-drain RFC being postponed for a future unified design that includes other functionality such as filtering-drain. So we’ll likely not add this to the standard library at this time: @rfcbot fcp close Consider experimenting with this API in a crate, possibly in https://crates.io/crates/itertools. |
Team member @SimonSapin has proposed to close this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
I had forgotten this was still open. It's a good idea to close it for now. I might bring it up again, if it fits together with an improved generalized drain. |
Rendered
Add an adapter
.exhausting()
toIterator
which causes the iterator to be driven to its end on drop. Before dropping it will act exactly like the source iterator.One of two RFCs for splitting the functionality of
drain
into two orthogonal APIs.Other RFC: #2369