Closed
Description
There is a huge section about working around this problem:
error[E0161]: cannot move a value of type std::ops::FnOnce() +
std::marker::Send: the size of std::ops::FnOnce() + std::marker::Send cannot be
statically determined
--> src/lib.rs:63:17
|
63 | (*job)();
| ^^^^^^
Currently (rustc 1.40.0 (73528e339 2019-12-16)
) you can just do job()
and it works perfectly, no need for FnBox
and call_box
workaround anymore.
Final code for Worker
impl:
type Job = Box<dyn FnOnce() + Send + 'static>;
// --snip --
impl Worker {
fn new(id: u32, receiver: Arc<Mutex<mpsc::Receiver<Job>>>) -> Worker {
let thread = thread::spawn(move || loop {
let job = receiver.lock().unwrap().recv().unwrap();
println!("Worker {} got a job; executing.", id);
job();
});
Worker { id, thread }
}
}
Metadata
Metadata
Assignees
Labels
No labels