This crate provides a [ShadowCountedIter] which counts every iteration to a hidden
counter. It is possible to create nested iterators which can commit their counter to their parent
iterator.
Unlike the std [std::iter::Enumerate] iterator, the [ShadowCountedIter] does not return the counter
to the user, instead it has to be queried with the [ShadowCountedIter::counter()] method.
We also provide a [IntoShadowCounted] extension trait which converts any iterator into a
[ShadowCountedIter].
Examples
Basic Counting
use ;
let vec = vec!;
let mut iter = vec.into_iter.shadow_counted;
while let Some = iter.next
assert_eq!;
Nested Counting
use ;
// Make a datastructure that may hold nested elements.
let items = &;
// iterate over the outer
let mut sc_iter = items.into_iter.shadow_counted;
assert_eq!;
// the 2nd element is `Node::Nested(..)'
let element = sc_iter.next.unwrap;
# assert_eq!;
// since we dont want to count `Nested` we substract one from the counter
sc_iter.add;
let Nested = element else ;
let mut nested_iter = nested.into_iter.nested_shadow_counted;
# assert_eq!;
assert_eq!;
# assert_eq!;
assert_eq!;
# assert_eq!;
// reaching the end, commit to the parent iter
assert_eq!;
// eventually a nested iter must be committed when its progress should be counted
nested_iter.commit;
// back to the outer
assert_eq!;
assert_eq!;
# assert_eq!;
# assert_eq!;
assert_eq!;