-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Document the behaviour of infinite iterators on potentially-computable methods #47547
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
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 | ||
|
||
| /// element to produce a result may not terminate, even on traits for which a | ||
| /// result is determinable in finite time. | ||
|
||
| /// | ||
| /// [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, | ||
|
||
| //! 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! | ||
|
||
| //! println!("The least positive number is {}.", least); | ||
| //! ``` | ||
|
Member
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
Contributor
Author
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.