Add `map` like functionality to read guards
whitfin opened this issue · 5 comments
One feature that the sync features of Tokio have is the ability to map
guards such as RwLockReadGuard
, which makes it possible to (e.g.) return a reference to a value inside a RwLock<HashMap<T>>
. Is it possible that something such as this is added to this library?
Tokio docs for this API: https://docs.rs/tokio/1.1.0/tokio/sync/struct.RwLockReadGuard.html#method.map
I'm okay with adding this, but there are some safety issues to keep in mind when implementing/reviewing.
Actually, some of the major (Mutex|RwLock)::map implementations were unsound. tokio-rs/tokio#3344, rust-lang/futures-rs#2239, Amanieu/parking_lot#259, Amanieu/parking_lot#258
I think the costs outweigh the benefits in this case, especially given the impossibility of implementing this behavior soundly. Especially since well-written code shouldn't have to use mapped guards.