Rollup merge of #52193 - Emerentius:step_by_note, r=alexcrichton

step_by: leave time of item skip unspecified

This gives us some leeway when optimizing. `StepBy<RangeFrom<_>>` is one case where this is needed.
This commit is contained in:
Mark Rousskov 2018-07-11 12:38:34 -06:00 committed by GitHub
commit 74cc821fd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -271,9 +271,30 @@ pub trait Iterator {
/// Creates an iterator starting at the same point, but stepping by
/// the given amount at each iteration.
///
/// Note that it will always return the first element of the iterator,
/// Note 1: The first element of the iterator will always be returned,
/// regardless of the step given.
///
/// Note 2: The time at which ignored elements are pulled is not fixed.
/// `StepBy` behaves like the sequence `next(), nth(step-1), nth(step-1), …`,
/// but is also free to behave like the sequence
/// `advance_n_and_return_first(step), advance_n_and_return_first(step), …`
/// Which way is used may change for some iterators for performance reasons.
/// The second way will advance the iterator earlier and may consume more items.
///
/// `advance_n_and_return_first` is the equivalent of:
/// ```
/// fn advance_n_and_return_first<I>(iter: &mut I, total_step: usize) -> Option<I::Item>
/// where
/// I: Iterator,
/// {
/// let next = iter.next();
/// if total_step > 1 {
/// iter.nth(total_step-2);
/// }
/// next
/// }
/// ```
///
/// # Panics
///
/// The method will panic if the given step is `0`.