Peek

struct Peek<T: Iterator>

A single-pass iterator with a one-element lookahead buffer.

has_peeked distinguishes an unfilled buffer from a buffered none at exhaustion. Repeated peek calls do not advance the underlying iterator; the next next returns the buffered result exactly once.

Properties

let inner: T

The source iterator advanced to fill the lookahead buffer.

let peeked: Element?

The buffered next element, when one has been read ahead.

Methods

mut func peek() -> &T.Element?

Fills and borrows the one-element lookahead buffer without advancing again.

A buffered none records permanent source exhaustion, so repeated peeks do not repeatedly call the source iterator.

View Source
pub mut func peek() -> &T.Element? {
	if self.has_peeked { return self.peeked }
	self.peeked = self.inner.next()
	self.has_peeked = true
	return self.peeked
}