考虑这个片段:
fn main() {
let arr_of_arr = [[1, 2], [3, 4]];
let res = arr_of_arr
.iter()
.flat_map(|arr| arr.iter())
.collect::<Vec<i32>>();
}
编译器错误是:
error[E0277]: the trait bound `std::vec::Vec<i32>: std::iter::FromIterator<&{integer}>` is not satisfied
--> src/main.rs:6:10
|
6 | .collect::<Vec<i32>>();
| ^^^^^^^ a collection of type `std::vec::Vec<i32>` cannot be built from an iterator over elements of type `&{integer}`
|
= help: the trait `std::iter::FromIterator<&{integer}>` is not implemented for `std::vec::Vec<i32>`
为什么这个片段不能编译?
特别是,我无法理解错误消息:什么类型代表&{integer}
?