79308645

Date: 2024-12-26 04:13:17
Score: 1
Natty:
Report link

As was mentioned in commend by @loganfsmyth, in order to call join on JoinHanlde you need to own it (because join "consumes" the JoinHandle). But get method on HashMap provides you with a borrow, not an ownership. So the solution would be to use remove to obtain owned value from HashMap

fn stop_server_command(id: usize) {
    if let Some((handler, signal)) = SERVER_INSTANCES.lock().unwrap().remove(&id) {
        signal.send(()).unwrap();
        handler.join().unwrap();
    }
}
Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @loganfsmyth
  • Low reputation (0.5):
Posted by: Babur Makhmudov