-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Consider allowing owned data in MappedMutexGuard
#289
Comments
Is the consideration any different for the mapped RwLock guards? I recently hit this issue because I wanted to keep the guard around a structure which borrows stored data, but is not such itself, but the current signature forbids such. |
Yes, rhe same issue described in the PR also applies to RwLock. |
Guessing you mean your objection on usability grounds in #290? I was mostly wondering if there were additional unsafety / concerns which would make the issue even more problematic for RwLock than it is for Mutex or if it was essentially the same, sorry for not being clear. |
I think it's essentially the same. |
I ran into this today on RwLock. I want to maintain (roughly) a |
I encountered this as well. Essentially, I need to implement iteration on a type struct Iter<'a>(X::Iter<'a>);
impl<'a> Iterator for Iter<'a> {
type Item = &'a YElem;
fn next(&mut self) -> Option<Self::Item> {
self.0.next().map(|x_elem| &x_elem.y_elem)
}
}
impl Y {
fn iter(&self) -> Iter<'_> {
let guard = self.lock.read();
Iter(RwLockReadGuard::map(guard, |x| x.iter())) // here, we need to return Iter<'_>, not &'_ …
}
} |
There is no reason that
MappedMutexGuard
needs to contain a*mut T
, it can just contain aT
. I believe that you may have to change the bound ofmap
like so:And you should also bound
MappedMutexGuard
'sT
parameter by'a
. This is strictly more general than the existing method, but will break anyone who explicitly specifies theT
parameter ofMappedMutexGuard
. To get around this, you could renameMappedMutexGuard
toOwnedMappedMutexGuard
and make the original name a type alias like so:The text was updated successfully, but these errors were encountered: