pub trait IntoIncBy<T: Copy + Default + Step>: RangeBounds<T> {
// Required method
fn inc_by<const STEP: usize>(self) -> IncBy<T, STEP> ⓘ;
}
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§
Sourcefn inc_by<const STEP: usize>(self) -> IncBy<T, STEP> ⓘ
fn inc_by<const STEP: usize>(self) -> IncBy<T, STEP> ⓘ
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);
}
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§
impl<T: Copy + Default + Step, R: RangeBounds<T>> IntoIncBy<T> for R
The actual implementation of IntoIncBy
for
RangeBounds
.