[Solved] How do I reverse a DoubleEndedIterator

I want to walk character indices from the back of a str. Currently I'm doing it procedurally, but I'd like to do it functionally.

I was expecting something like

trait DoubleEndedIterator {
    fn next_back(&mut self) -> Option<Item>;

    // ...

    // This is missing
    fn reverse(self) -> impl DoubleEndedIterator {
        // A wrapper struct that proxys next to next_back, and next_back to next
    }
}

Then you could do

my_str.char_indices().reverse().skip(3) // .other().adapters()....

I'm sure there's a good reason that such a thing doesn't exist, but I can't think what it might be.

Try to replace reverse() with rev().

2 Likes

aaaaaa I was looking for the method on DoubleEndedIterator not Iterator. Thanks!