Trait staticstep::IntoIncBy[][src]

pub trait IntoIncBy<T: Copy + Default + Step>: RangeBounds<T> {
    fn inc_by<const STEP: usize>(self) -> IncBy<T, STEP>
Notable traits for IncBy<T, STEP>
impl<T: Copy + Default + Step, const STEP: usize> Iterator for IncBy<T, STEP> type Item = T;
; }
Expand description

A subtrait of RangeBounds<T> where T is Copy + Default + Step that turns implementers of it into an instance of IncBy when inc_by is called. Currently, the blanket implementation of this trait exported from the crate for RangeBounds is the only possible useful implementation, but it was decided not to make it a “sealed” trait in case additional methods are added in the future that would be implementable by end-user code in a meaningfully varied way.

Required methods

Functionally equivalent to what step_by does when it is called through a primitive range, but written specifically with primitive ranges in mind such that it optimizes identically to a while loop in every case the author of this crate has examined so far.

Example usage:
// Exclusive, so prints: 'A C E'
for i in ('A'..'G').inc_by::<2>() {
  print!("{} ", i);
}

// Inclusive, so prints: '0 4 8 12'
for i in (0isize..=12isize).inc_by::<4>() {
  print!("{} ", i);
}

Implementors

The actual implementation of IntoIncBy for RangeBounds.