Trait IntoDecBy

Source
pub trait IntoDecBy<T: Copy + Default + Step>: RangeBounds<T> {
    // Required method
    fn dec_by<const STEP: usize>(self) -> DecBy<T, STEP> ;
}
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§

Source

fn dec_by<const STEP: usize>(self) -> DecBy<T, STEP>

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);
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Copy + Default + Step, R: RangeBounds<T>> IntoDecBy<T> for R

The actual implementation of IntoDecBy for RangeBounds.