Trait nommy::Buffer[][src]

pub trait Buffer<T>: Iterator<Item = T> + Sized {
    fn fast_forward(&mut self, n: usize);
fn peek_ahead(&mut self, i: usize) -> Option<T>; fn cursor(&mut self) -> Cursor<'_, T, Self>

Notable traits for Cursor<'a, T, B>

impl<'a, T, B: Buffer<T>> Iterator for Cursor<'a, T, B> type Item = T;
{ ... } }

Buffer is an extension to an Iterator, with the ability to create a cursor over the iterator, which can infinitely read from the iterator, preserving the buffer's position

use nommy::{Buffer, IntoBuf};
let mut buffer = (0..).into_buf();
let mut cursor1 = buffer.cursor();

// cursors act exactly like an iterator
assert_eq!(cursor1.next(), Some(0));
assert_eq!(cursor1.next(), Some(1));

// cursors can be made from other cursors
let mut cursor2 = cursor1.cursor();
assert_eq!(cursor2.next(), Some(2));
assert_eq!(cursor2.next(), Some(3));

// child cursors do not move the parent's iterator position
assert_eq!(cursor1.next(), Some(2));

// Same with the original buffer
assert_eq!(buffer.next(), Some(0));

Required methods

fn fast_forward(&mut self, n: usize)[src]

Skip the iterator ahead by n steps

fn peek_ahead(&mut self, i: usize) -> Option<T>[src]

Peek ahead by i spaces

Loading content...

Provided methods

fn cursor(&mut self) -> Cursor<'_, T, Self>

Notable traits for Cursor<'a, T, B>

impl<'a, T, B: Buffer<T>> Iterator for Cursor<'a, T, B> type Item = T;
[src]

Create a new cursor from this buffer any reads the cursor makes will not affect the next values the buffer will read

Loading content...

Implementors

impl<'a, T, B: Buffer<T>> Buffer<T> for Cursor<'a, T, B>[src]

impl<I: Iterator> Buffer<<I as Iterator>::Item> for Buf<I> where
    I::Item: Clone
[src]

Loading content...