]> git.lizzy.rs Git - rust.git/commit
Correct iterator adaptor Chain
authorUlrik Sverdrup <bluss@users.noreply.github.com>
Tue, 25 Aug 2015 01:56:35 +0000 (03:56 +0200)
committerUlrik Sverdrup <bluss@users.noreply.github.com>
Tue, 25 Aug 2015 17:07:24 +0000 (19:07 +0200)
commit35eb3e8b79c60ec18e724c7a68625d7cdf9300c0
treecbe9683058388284c4b11e0579c719eef98827b1
parent4c996499a1bcf747b12f8290eeff3024e59da529
Correct iterator adaptor Chain

The iterator protocol specifies that the iteration ends with the return
value `None` from `.next()` (or `.next_back()`) and it is unspecified
what further calls return. The chain adaptor must account for this in
its DoubleEndedIterator implementation.

It uses three states:

- Both `a` and `b` are valid
- Only the Front iterator (`a`) is valid
- Only the Back iterator (`b`) is valid

The fourth state (neither iterator is valid) only occurs after Chain has
returned None once, so we don't need to store this state.

Fixes #26316
src/libcore/iter.rs
src/libcoretest/iter.rs