struct MutexGuard<'a, T: 'a> {
data: &'a T,
//..
}
// Locking the mutex is explicit.
impl<T> Mutex<T> {
fn lock(&self) -> MutexGuard<T> {
// Lock the underlying OS mutex.
//..
// MutexGuard keeps a reference to self
MutexGuard {
data: self,
//..
}
}
}
Some of the code implies that MutexGuard references Mutex, but some other places imply that MutexGuard references T directly.
I believe the correct definition of MutexGuard 1 is
struct MutexGuard<'a, T: 'a> {
data: &'a Mutex<T>,
//..
}
And if MutexGuard contains a reference to Mutex rather than T, then the Deref implementation needs to be corrected as well.
Some of the code implies that MutexGuard references Mutex, but some other places imply that MutexGuard references T directly.
I believe the correct definition of MutexGuard 1 is
And if MutexGuard contains a reference to Mutex rather than T, then the
Derefimplementation needs to be corrected as well.Footnotes
alternatively:
define lock as
fn lock(&self) -> MutexGuard<Mutex<T>>or change the creation of the MutexGuard to
MutexGuard { data: self.<unnamed field for now, ... }↩