Ξενάγηση στη Rust Πίνακας Περιεχομένων

[Αμετάφραστο] The . Operator

The . operator is used in accessing fields and methods of a reference. It works a bit more subtly.

let f = Foo { value: 42 };
let ref_ref_ref_f = &&&f;
println!("{}", ref_ref_ref_f.value);

Whoa, why didn't we need to add *** before ref_ref_ref_f? This is because the . operator automatically dereferences a sequence of references. That last line is turned into the following by the compiler automatically.

println!("{}", (***ref_ref_ref_f).value);