The documentation for Peekable::next_if
says:
...
// `next_if` saves the value of the next item if it was not equal to `expected`.
assert_eq!(iter.next(), Some(1));
I don't see how this is related. The next
item is saved in Peekable
's peeked
field, but the iterator itself does not (should not?) advance when peeking. The next line with assert_eq(...)
shows exactly that.
Is it just badly worded or am I missing something about next_if
's actual behavior?
Another question I have is also about Peekable::next_if
. It's match statement looks like this:
match self.next() {
Some(matched) if func(&matched) => Some(matched),
other => {
// Since we called `self.next()`, we consumed `self.peeked`.
assert!(self.peeked.is_none());
self.peeked = Some(other);
None
}
}
What is the other
match arm? What matches against other
and what even is other
? My google-fu didn't help, so I'm a little bit lost.
Thank you.