struct A
{
map : RwLock<HashMap<K, V>>
}
I understand the semantics of using RwLock. This is what I want to accomplish:
I want to grab read lock, get a reference to value given a key, and then release the lock and then use the value. With the Rust RwLock semantics I need to use the value returned under the read lock. The goal for the lock here is to protect the map not the individual entries returned from the map. How can I accomplish that? Is that even possible?
For instance in Java I can do the following:
MyValue value = null;
rwLock.readLock().lock()
try
{
value = map.get("key");
}
finally
{
rwLock.readLock().unlock();
}
// use MyValue here
value.doSomething();
Can I do this in Rust? If so any pointers will be appreciated.