私は閉鎖を実験しています:
fn call_it(f: ||) {
f();
}
let klosure = || println("closure!");
call_it(klosure);
call_it(klosure); //Blows up here
klosure を call_it() に 2 回渡すと、クロージャー値が移動するため、コンパイラ エラーが発生します。
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