以前有一个问题是关于创建一个函数数组,其中函数从一个范围返回整数.最终的解决方案是做一个地图/收集到一个Vec<_>.
我有一个类似但不同的情况,我有相同的签名但不同的实现闭包.我试过这个:
let xs: Vec<_> = vec![
move |(x, y)| (y, x),
move |(x, y)| (1 - y, 1 - x),
];
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
error[E0308]: mismatched types
--> src/main.rs:4:9
|
4 | move |(x, y)| (1 - y, 1 - x),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected closure, found a different closure
|
= note: expected type `[closure@src/main.rs:3:9: 3:29]`
found type `[closure@src/main.rs:4:9: 4:37]`
= note: no two closures, even if identical, have the same type
= help: consider boxing your …Run Code Online (Sandbox Code Playgroud)