Our current drain and drain_filter APIs are partially eager in that they will self-exhaust themselves on drop. This forces two orthogonal behaviours together:
- Pick some elements out of a collection
- Clear all elements, that match a predicate / are inside a range or the entire collection.
It’s identical in behaviour to a collection.drain_nonexhausting().exhausting() iterator where the
Exhausting adapter drives the iter to completion.
This is a proposal to split this functionality up into two APIs, a non-self-exhausting drain and an iterator adapter for self-exhausting iters. Of course, the current drains will stay as-is for backwards compatibility.
I’d be happy to hear comments and suggestions for improvement. If you dislike either the self-exhausting iterators or the the lazy drain, please bear in mind that they are functionally independent from each other. I’ve put them together here because they are related and I would like to have one place for discussion about their interactions.