Rust question: Why doesn't Rust have a `RandomAccessIterator`? It seems to be there at some point but got removed: <https://www.cs.brandeis.edu/~cs146a/rust/doc-02-21-2015/std/iter/trait.RandomAccessIterator.html>.

And what is the alternative? Implementing `Index` for the iterator?

#rust #rustlang

std::iter::RandomAccessIterator - Rust

API documentation for the Rust `RandomAccessIterator` trait in crate `std`.

@lesley i think a good reason is to avoid aliasing. for example suppose you have a mutable vector `mut v: Vec<i32>`, and you call `.iter_mut()` on it. making the resulting iterator "random access" would allow you to call it twice with possibly the same index, which would violate the borrow checker