I'm trying to understand why println! has the same output when printing a reference of reference. Like the example below:
fn main() {
let value = 42;
let reference: &i32 = &value;
let reference2: &&i32 = &&value;
let reference3: &&&i32 = &reference2;
println!(" Value: {}", value); // output: 42
println!(" Reference: {}", reference); // output: 42
println!("Reference2: {}", reference2); // output: 42
println!("Reference3: {}", reference3); // output: 42
}
As pointed out in this question Why does printing a pointer print the same thing as printing the dereferenced pointer?: The implementation of Display for &T where T implements Display defers directly to the contents.
So, my question is, does the display implementation recursively deference a reference until reaches the value? And why println("{}", &&value)
does not print the address of value?