Trait staticstep::IntoDecBy[][src]

pub trait IntoDecBy<T: Copy + Default + Step>: RangeBounds<T> {
    fn dec_by<const STEP: usize>(self) -> DecBy<T, STEP>
Notable traits for DecBy<T, STEP>
impl<T: Copy + Default + Step, const STEP: usize> Iterator for DecBy<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 DecBy when dec_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 specifically in reverse and operating directly on ranges that are themselves syntactically “backwards”, while offering the same level of optimizability as inc_by.

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

// Inclusive, so prints: '4 1 -2'
for i in (4isize..=-4isize).dec_by::<3>() {
  print!("{} ", i);
}

Implementors

The actual implementation of IntoDecBy for RangeBounds.