rust-lang/rust

There should be a way to count backwards with a step using a range

Closed this issue · 2 comments

fn main() {
    for i in (0..10).step_by(2).rev() {
        println!("{}", i);
    }
}

produces the following error:

error: the trait `core::iter::DoubleEndedIterator` is not implemented for the type `core::iter::StepBy<_, core::ops::Range<_>>` [E0277]

Perhaps step_by() could produce a DoubleEndedIterator on ranges that are double-ended, but I don't know if this is possible.

#27741 has superceded this issue, so closing in favor of it.