You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MutPtr provides deref, which returns a &mut T, but nothing that returns a &T.
I'm working around it by calling MutPtr::with, dereferencing the pointer myself, and "smuggling" it out of the closure. Looking at the implementation of MutPtr I don't think I'm missing any validation by doing this, but it's not obvious from the API.
Ideally the current method would be called deref_mut and you could add deref, but I suppose if you don't want to make a breaking change, maybe you could add deref_const?
All of this is for a guard for a mutex that I'm testing; the guard stores a MutPtr from the mutex's UnsafeCell, and I'm currently implementing Deref and DerefMut roughly like so:
MutPtr provides
deref
, which returns a&mut T
, but nothing that returns a&T
.I'm working around it by calling
MutPtr::with
, dereferencing the pointer myself, and "smuggling" it out of the closure. Looking at the implementation ofMutPtr
I don't think I'm missing any validation by doing this, but it's not obvious from the API.Ideally the current method would be called
deref_mut
and you could addderef
, but I suppose if you don't want to make a breaking change, maybe you could addderef_const
?All of this is for a guard for a mutex that I'm testing; the guard stores a
MutPtr
from the mutex'sUnsafeCell
, and I'm currently implementingDeref
andDerefMut
roughly like so:The text was updated successfully, but these errors were encountered: