pub struct PeekState<'r, T> { /* private fields */ }
Expand description
Interface for the current state of the Peekable
iterator.
For a more detailed description, see Peekable::peek_state
.
Implementations§
Source§impl<'r, T> PeekState<'r, T>
impl<'r, T> PeekState<'r, T>
Sourcepub const fn is_full(&self) -> bool
pub const fn is_full(&self) -> bool
Returns true
if the Peekable
is two steps behind the underlying iterator (the
maximum lookahead).
This returning true does not imply runtime errors will take place, but that
subsequent peeks and the next two next
invocations will not touch the underlying
iterator.
Sourcepub const fn non_empty(&self) -> bool
pub const fn non_empty(&self) -> bool
Returns true
if the Peekable
is at least one step behind the underlying iterator.
Sourcepub const fn only_one(&self) -> bool
pub const fn only_one(&self) -> bool
Returns true
if the Peekable
is only one step behind the underlying iterator.
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true
if the Peekable
is not behind the underlying iterator.
This does not imply the underlying iterator has been exhausted
Sourcepub const fn num_peeked(&self) -> u8
pub const fn num_peeked(&self) -> u8
Returns the offset from the Peekable
iterator and the underlying iterator.
The offset is simply how far the Peekable
iterator has peeked; so if you
called peek_2
without advancing the Peekable
iterator this will return 2
.
§Example
assert_eq!(iter.peek_state().num_peeked(), 0);
iter.peek();
assert_eq!(iter.peek_state().num_peeked(), 1);
iter.next(); // decrements num_peeked as we move forward
assert_eq!(iter.peek_state().num_peeked(), 0);
iter.peek_2();
assert_eq!(iter.peek_state().num_peeked(), 2);
iter.peek();
// the peek is simply going to use what we've peeked previously,
// no mutation of state.
assert_eq!(iter.peek_state().num_peeked(), 2);
iter.next();
assert_eq!(iter.peek_state().num_peeked(), 1);
iter.next();
assert_eq!(iter.peek_state().num_peeked(), 0);