Add InfiniteIterator trait by 414owen · Pull Request #146668 · rust-lang/rust (original) (raw)
This enables more ExactSizeIterator instances, specifically, those
for Take, where the sub-iterator is infinite, and Zip where
one sub-iterator is infinite, and the other is exact sized.
Previously, in #146642,
I sought to add specific instances for Zip<Repeat<A>, I> and its
symmatrical mirror.
Introducing InfiniteIterator provides much broader support forExactSizeIterator.
For example,
[1, 2, 3].into_iter().chain(repeat(1)).take(5)
Will now happily resolve to an instance of ExactSizeIterator.
The downside of this approach is that, to avoid the overlapping instance
with Zip, I had to introduce a negative trait bound, which, IIUC,
isn't available outside of the compiler.
If anyone knows of a better way to handle the overlapping instances, or
a way I can expose something which triggers the negative instance, that
would be very helpful.
There's also a missing symmetrical instance for Chain. Solutions
are welcome.