So I can do this:
fn main() {
let a = 2;
let b = &a;
let c = b * 2; // I did not have to de-reference b by typing *b
dbg!(c);
}
I created b
to be a reference (pointer) to a
, and I was able to use the value b
points to without having to de-reference first.
It works but in trying to understand Rust more, I am curious why this automatic de-referencing occur? And what other scenario can I expect such automatic de-referencing?