Skip to content

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

Closed
@crumblingstatue

Description

@crumblingstatue
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions