237. Iterator::eq — Compare Two Sequences Without Collecting Them First
Comparing a Vec to an array, or a filtered iterator to an expected result? You don’t need to collect() both sides into the same type first.
The usual reflex is to force both sequences into matching containers so == works:
| |
Iterator::eq compares element-by-element straight off the iterators. No allocation, and the two sides don’t even have to be the same container type:
| |
It short-circuits, so a length or value mismatch stops early instead of walking both sequences to the end:
| |
The real payoff is comparing a lazy chain to an expected sequence without materializing it:
| |
And the same family does lexicographic ordering, again with no intermediate Vec:
| |
So the toolkit is eq, ne, cmp, lt, le, gt, ge — full equality and ordering over any two iterators, no collecting required.