這工作,因爲Iterator
實現rev()
其中self
是DoubleEndedIterator
:通過反向迭代一個&更多與vec.iter()
let vec: Vec<i32> = Vec::new();
for x in vec.iter().rev() {
//Do stuff
}
但是,如果我改變vec.iter().rev()
到&vec.rev()
它不能編譯,因爲:
no method named `rev` found for type `std::vec::Vec<i32>` in the current scope
此外:
the method `rev` exists but the following trait bounds were not satisfied: `std::vec::Vec<i32> : std::iter::Iterator`, `[i32] : std::iter::Iterator`
但沒有一個for循環隱含調用IntoIterator
? &vec
或vec.iter()
認爲慣用的鏽?