&(**node) address of indirection of indirection of variable. What does it mean?

Saw this code in docs. What is this doing? Is it similar as

value on node is a address of a, a == *node
value on a is a address of b, b == **node
address of b &b == &(**node)

I'm new to rust and also c pointers. Can anyone explain what is going on in &(**node)

In the case you linked:

    pub fn front(&self) -> Option<&T> {
        self.head.map(|node| unsafe { &(**node).element })

The type of node is &Shared<Node<T>>, and that parsed expression is actually like:

&( ( *( *node ) ).element )

So it's dereferencing the &, then dereferencing the Shared wrapper, then finding the .element member, and finally returning a reference to that element.

1 Like