pub trait StackingIteratorExt<T>: Iterator<Item = Instruction<T>> {
    // Provided methods
    fn collecting<C: Default + Clone + Extend<T> + Contract>(
        self
    ) -> Collecting<Self, C> 
       where Self: Sized { ... }
    fn operate<'c, C: Extend<T> + Contract>(
        &mut self,
        collection: &'c mut C
    ) -> Option<&'c C> { ... }
}
Expand description

Extra methods for iterators of Instructions.

Provided Methods§

source

fn collecting<C: Default + Clone + Extend<T> + Contract>( self ) -> Collecting<Self, C> where Self: Sized,

Converts an iterator of Instructions into an iterator of collections.

Example
use stacking_iterator::prelude::*;

let mut inst = vec![
    Instruction::Push('h'),
    Instruction::Push('e'),
    Instruction::Push('l'),
    Instruction::Push('l'),
    Instruction::Push('o'),
    Instruction::Yield,
    Instruction::Pop,
    Instruction::Yield,
].into_iter();
assert_eq!(inst.collecting().collect::<Vec<String>>(), ["hello", "hell"]);
source

fn operate<'c, C: Extend<T> + Contract>( &mut self, collection: &'c mut C ) -> Option<&'c C>

Performs the operations of the iterator until the next yield.

If the iterator ends before a yield is encountered, this returns None but still mutates the original collection.

Example
use stacking_iterator::prelude::*;

let mut inst = vec![
    Instruction::Push('h'),
    Instruction::Push('e'),
    Instruction::Push('l'),
    Instruction::Push('l'),
    Instruction::Push('o'),
    Instruction::Yield,
    Instruction::Pop,
    Instruction::Yield,
    Instruction::Pop,
    Instruction::Pop,
    Instruction::Pop,
    Instruction::Pop,
].into_iter();
let mut coll = String::new();
assert_eq!(inst.operate(&mut coll).map(|x| &**x), Some("hello"));
assert_eq!(coll, "hello");
assert_eq!(inst.operate(&mut coll).map(|x| &**x), Some("hell"));
assert_eq!(coll, "hell");
assert_eq!(inst.operate(&mut coll), None);
assert_eq!(coll, "");

Implementors§

source§

impl<T, I: Iterator<Item = Instruction<T>>> StackingIteratorExt<T> for I