Struct StepBy

#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct StepBy<I> { pub(in ::iter::adapters::step_by) iter: I, pub(in ::iter::adapters::step_by) step_minus_one: usize, pub(in ::iter::adapters::step_by) first_take: bool }

An iterator for stepping iterators by a custom amount.

This struct is created by the step_by method on Iterator. See its documentation for more.

Fields

iter: I

This field is guaranteed to be preprocessed by the specialized SpecRangeSetup::setup in the constructor. For most iterators that processing is a no-op, but for Range<{integer}> types it is lossy which means the inner iterator cannot be returned to user code. Additionally this type-dependent preprocessing means specialized implementations cannot be used interchangeably.

step_minus_one: usize

This field is step - 1, aka the correct amount to pass to nth when iterating. It MUST NOT be usize::MAX, as unsafe code depends on being able to add one without the risk of overflow. (This is important so that length calculations don't need to check for division-by-zero, for example.)

first_take: bool

Implementations

impl<I> StepBy<I>

fn new(iter: I, step: usize) -> StepBy<I>
fn original_step(&self) -> NonZero<usize>

The step that was originally passed to Iterator::step_by(step), aka self.step_minus_one + 1.

impl<I> StepBy<I> where I: ExactSizeIterator,

fn next_back_index(&self) -> usize

Trait Implementations

impl StepByBackImpl<Range<u16>> for StepBy<Range<u16>>

fn spec_next_back(&mut self) -> Option<Self::Item>
fn spec_nth_back(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_rfold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_rfold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByBackImpl<Range<u32>> for StepBy<Range<u32>>

fn spec_next_back(&mut self) -> Option<Self::Item>
fn spec_nth_back(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_rfold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_rfold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByBackImpl<Range<u8>> for StepBy<Range<u8>>

fn spec_next_back(&mut self) -> Option<Self::Item>
fn spec_nth_back(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_rfold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_rfold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByBackImpl<Range<usize>> for StepBy<Range<usize>>

fn spec_next_back(&mut self) -> Option<Self::Item>
fn spec_nth_back(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_rfold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_rfold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByBackImpl<RangeIter<u16>> for StepBy<RangeIter<u16>>

fn spec_next_back(&mut self) -> Option<Self::Item>
fn spec_nth_back(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_rfold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_rfold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByBackImpl<RangeIter<u8>> for StepBy<RangeIter<u8>>

fn spec_next_back(&mut self) -> Option<Self::Item>
fn spec_nth_back(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_rfold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_rfold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByBackImpl<RangeIter<usize>> for StepBy<RangeIter<usize>>

fn spec_next_back(&mut self) -> Option<Self::Item>
fn spec_nth_back(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_rfold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_rfold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByImpl<Range<u16>> for StepBy<Range<u16>>

fn spec_next(&mut self) -> Option<u16>
fn spec_size_hint(&self) -> (usize, Option<usize>)
fn spec_nth(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_fold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_fold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByImpl<Range<u32>> for StepBy<Range<u32>>

fn spec_next(&mut self) -> Option<u32>
fn spec_size_hint(&self) -> (usize, Option<usize>)
fn spec_nth(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_fold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_fold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByImpl<Range<u64>> for StepBy<Range<u64>>

fn spec_next(&mut self) -> Option<u64>
fn spec_size_hint(&self) -> (usize, Option<usize>)
fn spec_nth(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_fold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_fold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByImpl<Range<u8>> for StepBy<Range<u8>>

fn spec_next(&mut self) -> Option<u8>
fn spec_size_hint(&self) -> (usize, Option<usize>)
fn spec_nth(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_fold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_fold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByImpl<Range<usize>> for StepBy<Range<usize>>

fn spec_next(&mut self) -> Option<usize>
fn spec_size_hint(&self) -> (usize, Option<usize>)
fn spec_nth(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_fold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_fold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByImpl<RangeIter<u16>> for StepBy<RangeIter<u16>>

fn spec_next(&mut self) -> Option<u16>
fn spec_size_hint(&self) -> (usize, Option<usize>)
fn spec_nth(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_fold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_fold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByImpl<RangeIter<u32>> for StepBy<RangeIter<u32>>

fn spec_next(&mut self) -> Option<u32>
fn spec_size_hint(&self) -> (usize, Option<usize>)
fn spec_nth(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_fold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_fold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByImpl<RangeIter<u64>> for StepBy<RangeIter<u64>>

fn spec_next(&mut self) -> Option<u64>
fn spec_size_hint(&self) -> (usize, Option<usize>)
fn spec_nth(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_fold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_fold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByImpl<RangeIter<u8>> for StepBy<RangeIter<u8>>

fn spec_next(&mut self) -> Option<u8>
fn spec_size_hint(&self) -> (usize, Option<usize>)
fn spec_nth(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_fold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_fold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl StepByImpl<RangeIter<usize>> for StepBy<RangeIter<usize>>

fn spec_next(&mut self) -> Option<usize>
fn spec_size_hint(&self) -> (usize, Option<usize>)
fn spec_nth(&mut self, n: usize) -> Option<Self::Item>
fn spec_try_fold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_fold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl<I> DoubleEndedIterator for StepBy<I> where I: DoubleEndedIterator + ExactSizeIterator,

fn next_back(&mut self) -> Option<Self::Item>
fn nth_back(&mut self, n: usize) -> Option<Self::Item>
fn try_rfold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn rfold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    Self: Sized,
    F: FnMut(Acc, Self::Item) -> Acc,

impl<I> ExactSizeIterator for StepBy<I> where I: ExactSizeIterator,

impl<I> FusedIterator for StepBy<I> where I: FusedIterator,

impl<I> Iterator for StepBy<I> where I: Iterator,

type Item = <I as Iterator>::Item;
fn next(&mut self) -> Option<Self::Item>
fn size_hint(&self) -> (usize, Option<usize>)
fn nth(&mut self, n: usize) -> Option<Self::Item>
fn try_fold<Acc, F, R>(&mut self, acc: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn fold<Acc, F>(self, acc: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl<I> TrustedLen for StepBy<I> where I: Iterator + TrustedRandomAccess,

impl<I: Clone> Clone for StepBy<I>

fn clone(&self) -> StepBy<I>

impl<I: Debug> Debug for StepBy<I>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<I: DoubleEndedIterator + ExactSizeIterator> StepByBackImpl<I> for StepBy<I>

type Item = <I as Iterator>::Item;
fn spec_next_back(&mut self) -> Option<Self::Item>
fn spec_nth_back(&mut self, n: usize) -> Option<I::Item>
fn spec_try_rfold<Acc, F, R>(&mut self, init: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_rfold<Acc, F>(self, init: Acc, f: F) -> Acc
where
    Self: Sized,
    F: FnMut(Acc, I::Item) -> Acc,

impl<I: Iterator> StepByImpl<I> for StepBy<I>

type Item = <I as Iterator>::Item;
fn spec_next(&mut self) -> Option<I::Item>
fn spec_size_hint(&self) -> (usize, Option<usize>)
fn spec_nth(&mut self, n: usize) -> Option<I::Item>
fn spec_try_fold<Acc, F, R>(&mut self, acc: Acc, f: F) -> R
where
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn spec_fold<Acc, F>(self, acc: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

Auto Trait Implementations

impl<I> Freeze for StepBy<I> where I: Freeze,

impl<I> RefUnwindSafe for StepBy<I> where I: RefUnwindSafe,

impl<I> Send for StepBy<I> where I: Send,

impl<I> Sync for StepBy<I> where I: Sync,

impl<I> Unpin for StepBy<I> where I: Unpin,

impl<I> UnsafeUnpin for StepBy<I> where I: UnsafeUnpin,

impl<I> UnwindSafe for StepBy<I> where I: UnwindSafe,

Blanket Implementations

impl<I> IntoIterator for StepBy<I> where I: Iterator,

type Item = <I as Iterator>::Item;
type IntoIter = I;
fn into_iter(self) -> I

impl<T> Any for StepBy<I> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for StepBy<I> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for StepBy<I> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for StepBy<I> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for StepBy<I>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for StepBy<I> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for StepBy<I>

impl<T, U> Into<U> for StepBy<I> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for StepBy<I> where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for StepBy<I> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>