【发布时间】:2020-09-05 16:33:14
【问题描述】:
我想使用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
});
【问题讨论】:
-
将
iter()替换为into_iter()。
标签: rust