我想使用
foreach
等待线程终止。但是,出现了以下错误,无法实现。
请告诉我。cannot move out of `*handle` which is behind a shared reference move occurs because `*handle` has type `std::thread::JoinHandle<()>`, which does not implement the `Copy` trait
let mut handles = Vec::new();
handles.push(thread::spawn(move || {
let mut data = snd_rx.recv().unwrap();
data += 1;
let _ = rcv_tx.send(data);
}));
handles.iter().for_each(|handle| {
let _ = handle.join(); // <- Error occurred
});
into_iter()
替换iter()
。 - user4815162342