Skip to content

Commit ba6957c

Browse files
authored
Rollup merge of #87034 - mgeier:doc-step_by, r=JohnTitor
DOC: fix hypothetical Rust code in `step_by()` docstring I don't know how important that is, but if I'm not mistaken, the hypothetical code in the docstring of `step_by()` (see https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.step_by) isn't correct. I guess writing `next()` instead of `self.next()` isn't a biggie, but this would also imply that `advance_n_and_return_first()` is a method, which AFAICT it isn't. I've also done some re-formatting in a separate commit and a parameter renaming in yet another commit. Feel free to take or leave any combination of those commits.
2 parents b2b7c85 + 46abc12 commit ba6957c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

library/core/src/iter/traits/iterator.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -333,21 +333,22 @@ pub trait Iterator {
333333
/// regardless of the step given.
334334
///
335335
/// Note 2: The time at which ignored elements are pulled is not fixed.
336-
/// `StepBy` behaves like the sequence `next(), nth(step-1), nth(step-1), …`,
337-
/// but is also free to behave like the sequence
338-
/// `advance_n_and_return_first(step), advance_n_and_return_first(step), …`
336+
/// `StepBy` behaves like the sequence `self.next()`, `self.nth(step-1)`,
337+
/// `self.nth(step-1)`, …, but is also free to behave like the sequence
338+
/// `advance_n_and_return_first(&mut self, step)`,
339+
/// `advance_n_and_return_first(&mut self, step)`, …
339340
/// Which way is used may change for some iterators for performance reasons.
340341
/// The second way will advance the iterator earlier and may consume more items.
341342
///
342343
/// `advance_n_and_return_first` is the equivalent of:
343344
/// ```
344-
/// fn advance_n_and_return_first<I>(iter: &mut I, total_step: usize) -> Option<I::Item>
345+
/// fn advance_n_and_return_first<I>(iter: &mut I, n: usize) -> Option<I::Item>
345346
/// where
346347
/// I: Iterator,
347348
/// {
348349
/// let next = iter.next();
349-
/// if total_step > 1 {
350-
/// iter.nth(total_step-2);
350+
/// if n > 1 {
351+
/// iter.nth(n - 2);
351352
/// }
352353
/// next
353354
/// }

0 commit comments

Comments
 (0)