Closed
Description
This code...
use std::thread;
struct Philosopher {
name: String,
}
impl Philosopher {
fn new(name: &str) -> Philosopher {
Philosopher {
name: name.to_string(),
}
}
fn eat(&self) {
println!("{} is eating.", self.name);
thread::sleep_ms(1000);
println!("{} is done eating.", self.name);
}
}
fn main() {
let philosophers = vec![
Philosopher::new("Baruch Spinoza"),
Philosopher::new("Gilles Deleuze"),
Philosopher::new("Karl Marx"),
Philosopher::new("Friedrich Nietzsche"),
Philosopher::new("Michel Foucault"),
];
let handles: Vec<_> = philosophers.into_iter().map(|p| {
thread::spawn(move || {
p.eat();
});
}).collect();
for h in handles {
h.join().unwrap();
}
}
... leads to:
src/main.rs:39:11: 39:17 error: type `()` does not implement any method in scope named `join`
src/main.rs:39 h.join().unwrap();
^~~~~~
error: aborting due to previous error
Could not compile `Philosopher`.
Actually the error lies in line 35 in the semicolon });
at the end:
thread::spawn(move || {
p.eat();
});