-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Document the behaviour of infinite iterators on potentially-computable methods #47547
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,10 @@ fn _assert_is_object_safe(_: &Iterator<Item=()>) {} | |
/// This is the main iterator trait. For more about the concept of iterators | ||
/// generally, please see the [module-level documentation]. In particular, you | ||
/// may want to know how to [implement `Iterator`][impl]. | ||
/// | ||
/// Note: Methods on infinite iterators that generally require traversing every | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought it was probably helpful to point this out in the trait documentation, but if this feels like too much of a niche case to mention here, the module-level documentation could be sufficient. |
||
/// element to produce a result may not terminate, even on traits for which a | ||
/// result is determinable in finite time. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that the trait's doc-comment is essentially just a redirect to the module docs, I don't think this note needs to be here as well. Maybe mention diverging in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I was divided 50:50 on this one. I've taken it out and replaced it with a comment on |
||
/// | ||
/// [module-level documentation]: index.html | ||
/// [impl]: index.html#implementing-iterator | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,8 +297,22 @@ | |
//! ``` | ||
//! | ||
//! This will print the numbers `0` through `4`, each on their own line. | ||
//! | ||
//! Bear in mind that methods on infinite iterators, even those for which a | ||
//! result can be computed in finite time, may not terminate. Specifically, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the words "can be computed" lead to a "well, how do I compute it then?" feeling. Perhaps it could be phrased along the lines of "even if a value for them could be determined mathematically", or something? And instead of "may not terminate", what about being more explicit, with something like "will not return successfully"? (I don't know if talking about the different ways something could diverge would be useful.) |
||
//! methods such as [`min`], which in the general case require traversing | ||
//! every element in the iterator, are likely never to terminate for any | ||
//! infinite iterators. | ||
//! | ||
//! ``` | ||
//! let positives = 1..; | ||
//! let least = positives.min().unwrap(); // Oh no! An infinite loop! | ||
//! // `positives.min` causes an infinite loop, so we won't reach this point! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: in debug mode this panics due to overflow, and doesn't infinite-loop |
||
//! println!("The least positive number is {}.", least); | ||
//! ``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block should be marked as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, of course! |
||
//! | ||
//! [`take`]: trait.Iterator.html#method.take | ||
//! [`min`]: trait.Iterator.html#method.min | ||
|
||
#![stable(feature = "rust1", since = "1.0.0")] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing white space.