PeekState

Struct PeekState 

Source
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>

Source

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.

Source

pub const fn non_empty(&self) -> bool

Returns true if the Peekable is at least one step behind the underlying iterator.

Source

pub const fn only_one(&self) -> bool

Returns true if the Peekable is only one step behind the underlying iterator.

Source

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

Source

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);

Trait Implementations§

Source§

impl<'r, T: Clone> Clone for PeekState<'r, T>

Source§

fn clone(&self) -> PeekState<'r, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'r, T: Copy> Copy for PeekState<'r, T>

Auto Trait Implementations§

§

impl<'r, T> Freeze for PeekState<'r, T>

§

impl<'r, T> RefUnwindSafe for PeekState<'r, T>
where T: RefUnwindSafe,

§

impl<'r, T> Send for PeekState<'r, T>
where T: Sync,

§

impl<'r, T> Sync for PeekState<'r, T>
where T: Sync,

§

impl<'r, T> Unpin for PeekState<'r, T>

§

impl<'r, T> UnwindSafe for PeekState<'r, T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.