Skip to content

Commit

Permalink
Rollup merge of #135118 - ranger-ross:better-docs-on-iter-fns, r=jhpratt
Browse files Browse the repository at this point in the history
Clarified the documentation on `core::iter::from_fn` and `core::iter::successors`

This PR clarifies the closure requirements for `core::iter::from_fn` and `core::iter::successors`.

`std::iter::successors` in particular is a bit difficult to understand if you are not already familiar with the signature of [`checked_mul`](https://docs.rs/num/latest/num/trait.CheckedMul.html) used in the example.

See #135087
  • Loading branch information
jhpratt authored Jan 5, 2025
2 parents b9f971a + 6243c0f commit af9293f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/core/src/iter/sources/from_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::fmt;
/// Creates a new iterator where each iteration calls the provided closure
/// `F: FnMut() -> Option<T>`.
///
/// The iterator will yield the `T`s returned from the closure.
///
/// This allows creating a custom iterator with any behavior
/// without using the more verbose syntax of creating a dedicated type
/// and implementing the [`Iterator`] trait for it.
Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/sources/successors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::iter::FusedIterator;
///
/// The iterator starts with the given first item (if any)
/// and calls the given `FnMut(&T) -> Option<T>` closure to compute each item’s successor.
/// The iterator will yield the `T`s returned from the closure.
///
/// ```
/// use std::iter::successors;
Expand Down

0 comments on commit af9293f

Please sign in to comment.