I'm looking at the Condvar
example and am curious how the tuples pair
and pair2
are destructured:
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair2 = pair.clone();
// ...
thread::spawn(move|| {
let &(ref lock, ref cvar) = &*pair2;
// ...
}
Removing the &
from pair2
:
let &(ref lock, ref cvar) = *pair2;
gives a compiler error as I expected:
11 | let &(ref lock, ref cvar) = *pair2;
| ^^^^^^^^^^^^^^^^^^^^^ expected tuple, found reference
|
= note: expected type `(std::sync::Mutex<bool>, std::sync::Condvar)`
found type `&_`
However, it seems to compile and run fine if the &
around the tuple is removed:
let (ref lock, ref cvar) = &*pair2;
or if both of the &
's are removed:
let (ref lock, ref cvar) = *pair2;
or even with
let (lock, cvar) = &*pair2;
Is the compiler is helping us in the latter cases?