|
1 | 1 | use crate::fmt;
|
2 | 2 | use crate::iter::FusedIterator;
|
3 | 3 |
|
4 |
| -/// Creates a new iterator where each successive item is computed based on the preceding one. |
| 4 | +/// Creates an iterator which, starting from an initial item, |
| 5 | +/// computes each successive item from the preceding one. |
5 | 6 | ///
|
6 |
| -/// The iterator starts with the given first item (if any) |
7 |
| -/// and calls the given `FnMut(&T) -> Option<T>` closure to compute each item’s successor. |
8 |
| -/// The iterator will yield the `T`s returned from the closure. |
| 7 | +/// This iterator stores an optional item (`Option<T>`) and a successor closure (`impl FnMut(&T) -> Option<T>`). |
| 8 | +/// Its `next` method returns the stored optional item and |
| 9 | +/// if it is `Some(val)` calls the stored closure on `&val` to compute and store its successor. |
| 10 | +/// The iterator will apply the closure successively to the stored option's value until the option is `None`. |
| 11 | +/// This also means that once the stored option is `None` it will remain `None`, |
| 12 | +/// as the closure will not be called again, so the created iterator is a [`FusedIterator`]. |
| 13 | +/// The iterator's items will be the initial item and all of its successors as calculated by the successor closure. |
9 | 14 | ///
|
10 | 15 | /// ```
|
11 | 16 | /// use std::iter::successors;
|
|
24 | 29 | Successors { next: first, succ }
|
25 | 30 | }
|
26 | 31 |
|
27 |
| -/// A new iterator where each successive item is computed based on the preceding one. |
| 32 | +/// An iterator which, starting from an initial item, |
| 33 | +/// computes each successive item from the preceding one. |
28 | 34 | ///
|
29 | 35 | /// This `struct` is created by the [`iter::successors()`] function.
|
30 | 36 | /// See its documentation for more.
|
|
0 commit comments