This works because Iterator
implements rev()
where self
is a DoubleEndedIterator
:
let vec: Vec<i32> = Vec::new();
for x in vec.iter().rev() {
//Do stuff
}
However, if I change vec.iter().rev()
to &vec.rev()
it won't compile because:
no method named `rev` found for type `std::vec::Vec<i32>` in the current scope
Furthermore:
the method `rev` exists but the following trait bounds were not satisfied: `std::vec::Vec<i32> : std::iter::Iterator`, `[i32] : std::iter::Iterator`
But doesn't a for loop implicitly call IntoIterator
? Is &vec
or vec.iter()
considered idiomatic Rust?
&vec
isn't an iterator (onlyIntoIterator
). – Tibetan