What's the ExactSizeIterator meaning for a non-FusedIterator?


I have a question. If a Iterator is not a FusedIterator, what's the actual meaning of ExactSizeIterator?

For example, if we can fully know the limited items sequence of an iterator, as follows,

assert_eq!(iter.next(), Some(0));
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), Some(4));
assert_eq!(iter.next(), None); // after this line, iter.next() return None forever.

Is this iter can be an ExactSizeIterator? If so, the iter.len() should be 2 or 5?

  1. Everything else like count uses the first None as the length.
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.