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

Fix documentation for Iterator::count(). #66094

Merged
merged 3 commits into from
Nov 13, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/libcore/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ pub trait Iterator {
/// Consumes the iterator, counting the number of iterations and returning it.
///
/// This method will evaluate the iterator until its [`next`] returns
/// [`None`]. Once [`None`] is encountered, `count()` returns the number of
/// times it called [`next`].
/// [`None`]. Once [`None`] is encountered, `count()` returns one less than the
Copy link
Member

Choose a reason for hiding this comment

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

This feels like a confusing way to state things. Perhaps something like this would be better: "count() will call [next()] until [None] is encountered, returning the number of times it saw Some(_)."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's a good point. Just replacing count() to "This method" at the beginning feels aesthetically more pleasing. Furthermore using a hyperlink reference to Some is probably beneficial. So may I suggest: "This method will call [next] repeatedly until [None] is encountered, returning the number of times it saw [Some]."

Copy link
Member

Choose a reason for hiding this comment

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

Sounds great! <3

/// number of times it called [`next`]. Note that [`next`] has to be called at
/// least once even if the iterator does not have any elements.
///
/// [`next`]: #tymethod.next
/// [`None`]: ../../std/option/enum.Option.html#variant.None
Expand Down