Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add Iterator::size_hint example #28028

Merged
merged 1 commit into from
Aug 27, 2015
Merged

doc: add Iterator::size_hint example #28028

merged 1 commit into from
Aug 27, 2015

Conversation

tshepang
Copy link
Member

No description provided.

@rust-highfive
Copy link
Contributor

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

///
/// ```
/// let a = [1, 2, 3, 4, 5];
/// assert_eq!((5, Some(5)), a.iter().size_hint());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not good example at all. While in practice this particular iterator over this particular data type will always return the exact size bounds, the purpose of this method (as the name implies) is for it to act as a hint. None of that hint-ness is reflected in this example.

Perhaps various iterator adaptors would make the hint more interesting and fitting? For example:

let iterator = (0..10).filter(|x| x % 2 == 0).chain(15..20);
iterator.size_hint() // returns (5, Some(15)) and the actual length of 10 is indeed in-bounds.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kool, thanks

@alexcrichton
Copy link
Member

@bors: r+ 0ca1cae

@bors
Copy link
Collaborator

bors commented Aug 27, 2015

⌛ Testing commit 0ca1cae with merge 40fd4d6...

@bors bors merged commit 0ca1cae into rust-lang:master Aug 27, 2015
@tshepang tshepang deleted the add-size_hint-example branch August 27, 2015 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants