Open
Description
Let's say I have the following code:
struct Foo {
items: RwLock<Vec<Item>>,
}
impl Foo {
pub fn bar(&self) {
for i in self.items.read().unwrap().deref() {
self.some_method_that_will_endup_calling_baz(i);
}
}
fn baz(&self, id: u32) {
self.items.read().unwrap().iter().find(|i| i.id() == id);
}
}
If someone call bar
it may cause a panic in baz
because the items
is already locked by bar
. The above code will be working if items
is not putting behind RwLock
but I will not be able to push the item into items
. If I lock the Foo
instead of its field it will solve this problem but it will cumbersome to work with Foo
if most of it fields is immutable.