Why do I need to clone tx
? I moved it. I cannot use it in my main thread anymore.
use std::sync::mpsc::{channel, Sender};
fn main() {
let (tx, _rx) = channel();
std::thread::spawn(move || {
takes_closure(|| Foo { sender: tx });
});
}
struct Foo {
sender: Sender<()>,
}
fn takes_closure(_: impl FnMut() -> Foo) {}
This has the error:
error[E0507]: cannot move out of captured variable in an `FnMut` closure
--> src/main.rs:7:40
|
4 | let (tx, _rx) = channel();
| -- captured outer variable
...
7 | takes_closure(|| Foo { sender: tx });
| ^^ cannot move out of captured variable in an `FnMut` closure