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 Instruction
s.
Provided Methods§
sourcefn collecting<C: Default + Clone + Extend<T> + Contract>(
self
) -> Collecting<Self, C> ⓘwhere
Self: Sized,
fn collecting<C: Default + Clone + Extend<T> + Contract>( self ) -> Collecting<Self, C> ⓘwhere Self: Sized,
Converts an iterator of Instruction
s 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"]);
sourcefn operate<'c, C: Extend<T> + Contract>(
&mut self,
collection: &'c mut C
) -> Option<&'c C>
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, "");