My struct is defined like this :
struct MyStruct {
...
clients: RwLock<HashMap<u32, RefCell<Client>>>,
...
}
I would like to write a function "find_client_by_id(id)" where I could get the client object directly. This is my final goal. For now, here is what I have to do every time that I want to access a client :
let mut clients = self.clients.read().unwrap();
if let Some(client_ref) = clients.get(&client_id) {
let client = RefCell::borrow_mut(&client_ref);
client.call_my_function_on_client_object(); // Here I can call client's functions
}
What I would like, is something like this :
let mut client = self.find_client_by_id(client_id);
if client.is_some() {
client.unwrap().call_my_function_on_client_object();
}
Is it possible ? All my tries ended up with compilation error. Thanks