Why is the lower bound on Iterator::size_hint useful?

I get that the upper bound is used for preallocating. Cant imagine why someone would want to know that the smallest it could possibly be is.

Actually in the current implementation the lower bound is used for preallocating. I don't know uses of the upper bound.

6 Likes

It's not. The upper bound can be infinite or unknown, neither of which can be used for pre-allocation.

1 Like

Right. I assumed in the case of some.

Although i can also see hypothetically now why you may want both...

Take upper bound if some, else use lower bound

But as @SkiFire13 pointed out, the upper bound is not used this way, so do you know of a purpose (in std at least) for upper bound?

No: Is .size_hint().1 ever used? - libs - Rust Internals

3 Likes

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.