How do you destructure a reference to Arc?

Hi everyone,

I have a problem trying to destructure a reference to an Arc:

fn thread_method (queue: &Arc<(Mutex<VecDeque<u8>>, Condvar)>) {
    let &(ref l, ref cv) = &*queue;

The compiler gives me the following error:

src/ 51:25 error: mismatched types:
 expected `alloc::arc::Arc<(std::sync::mutex::Mutex<collections::vec_deque::VecDeque<u8>>, std::sync::condvar::Condvar)>`,
    found `(_, _)`
(expected struct `alloc::arc::Arc`,
    found tuple) [E0308]
src/     let &(ref l, ref cv) = &*queue;

Do you know how I have to destructure the contents of the Arc?

Thank you very much

Nevermind, I've found it: &**queue. I didn't know you had double pointers in Rust.

1 Like

For that, the first dereference (*) is turning &Arc into Arc, and the second dereference is turning Arc into (Mutex<VecDeque<u8>>, Condvar). It isn't exactly a 'double pointer' per se, but rather a reference to something which implements Deref<>.


Ok, thank you very much for the clarification.

FYI, you don't need the &. You should be able to say:

let (ref l, ref cv) = **queue;

Good! Thanks. I had taken as example the code from Condvar in std::sync - Rust