我正在尝试关闭:
fn call_it(f: ||) {
f();
}
let klosure = || println("closure!");
call_it(klosure);
call_it(klosure); //Blows up here
由于闭包值被移动,将 klosure 两次传递给 call_it() 会导致编译器错误:
closures.rs:16:13: 16:20 error: use of moved value: `klosure`
closures.rs:16 call_it(klosure);
^~~~~~~
closures.rs:15:13: 15:20 note: `closure` moved here because it has type `||`, which is a non-copyable stack closure (capture it in a new closure, e.g. `|x| f(x)`, to override)
closures.rs:15 call_it(klosure);
^~~~~~~
编译器实际上就如何解决问题提出了建议,但我还没有找到成功应用它的方法。
有什么建议么?:D