pub fn rciter<I>(iterable: I) -> RcIter<I::IntoIter> where I: IntoIterator
Return an iterator inside a
RcIter can be cloned, and each clone will refer back to the
same original iterator.
RcIter allows doing interesting things like using
.zip() on an iterator with
itself, at the cost of runtime borrow checking.
(If it is not obvious: this has a performance penalty.)
Iterator element type is
use itertools::rciter; let mut rit = rciter(0..9); let mut z = rit.clone().zip(rit.clone()); assert_eq!(z.next(), Some((0, 1))); assert_eq!(z.next(), Some((2, 3))); assert_eq!(z.next(), Some((4, 5))); assert_eq!(rit.next(), Some(6)); assert_eq!(z.next(), Some((7, 8))); assert_eq!(z.next(), None);
Panics in iterator methods if a borrow error is encountered,
but it can only happen if the
RcIter is reentered in for example
i.e. if it somehow participates in an “iterator knot” where it is an adaptor of itself.