# \`size\_hint\`, correctness, reproducibility and documentation

**URL:** <https://internals.rust-lang.org/t/size-hint-correctness-reproducibility-and-documentation/8058>\
**Category:** libs\
**Created:** [July 25, 2018, 12:17pm UTC](https://internals.rust-lang.org/t/size-hint-correctness-reproducibility-and-documentation/8058 "2018-07-25T12:17:15Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [July 25, 2018, 2:37pm UTC](https://internals.rust-lang.org/t/size-hint-correctness-reproducibility-and-documentation/8058/6 "2018-07-25T14:37:49Z")

</div>

> [@dhardy](#):
>
> Is it allowable to incorrectly return `None` when randomly choosing an element from an iterator whose length is less than the claimed lower bound?

Yes. Garbage in, garbage out: of someone gives you an iterator that doesn't implement Iterator correctly, you're also allowed to not behave correctly. The only thing you're not allowed to do is be memory-unsafe.

Some examples:

- if the size\_hint says there will be N elements, you can OOM for the N even if it was actually empty

- if it claims to be ExactSizeIterator, you can loop to the len calling `.next().unwrap()`, which might panic or skip some (but you cannot call `.next().unwrap_or_else(unreachable_unchecked)`)

---

_[View the full topic](https://internals.rust-lang.org/t/size-hint-correctness-reproducibility-and-documentation/8058)._
