#iterator #back #items #onto #pushed #push-back #pushback

pushback-iter

An iterator with a push_back method that allows items to be pushed back onto the iterator

2 unstable releases

0.2.0 Nov 16, 2020
0.1.0 Nov 13, 2020

#7 in #onto

MIT/Apache

8KB
127 lines

Crate Documentation CI

pushback-iter

An iterator with a push_back(item) method that allows items to be pushed back onto the iterator.


lib.rs:

This create providers an implementation of PushBackIterator which is a wrapper around an iterator which allows for items to be pushed back onto the iterator to be consumed on subsequent call to next().

use pushback_iter::PushBackIterator;

let items = vec![1, 2, 3];
let mut iter = PushBackIterator::from(items.into_iter());

let item = iter.next().unwrap();
assert_eq!(item, 1);

iter.push_back(item);
assert_eq!(iter.next(), Some(1));

iter.push_back(6);
iter.push_back(5);
assert_eq!(iter.next(), Some(5));
assert_eq!(iter.next(), Some(6));
assert_eq!(iter.next(), Some(2));

No runtime deps