I am trying to pass enum type data to a thread using channels in Rust, but I keep getting the following error when I run the program (it compiles fine),
thread 'thread 'main' panicked at '' panicked at 'attempted to leave type
internal::Local
uninitialized, which is invalid. Attempted to leave typeinternal::Local
uninitialized, which is invalid'
Here is the code snippet,
use std::thread;
use crossbeam_channel::unbounded;
enum Message {
Sum(i64, i64),
Quit
}
fn main() {
let (sender, receiver) = unbounded();
let worker = thread::spawn(move || loop {
match receiver.recv() {
Some(msg) => match msg {
Message::Sum(a, b) => println!("{} + {} = {}", a, b, a+b),
Message::Quit => {
println!("Thread Terminating");
break
},
},
None => {
print!("Didn't receive or unable to read the message");
break;
}
}
}
);
sender.send(Message::Sum(10, 21));
sender.send(Message::Quit);
worker.join();
}
And here's the relevant part of Cargo.toml
:
[dependencies]
crossbeam-channel = "0.2.5"