Here is my code, where it works well with explicit de-reference and
without explicit de-refernce. Can any one confirm this ?
Thanks,
S.Gopinath
struct Rectangle {
x : f64,
y : f64,
}
fn main()
{
let x1 = Rectangle {x : 10.1, y: 20.2};
let y1 = &x1;
//y is a reference variable which points to x
print_rect(y1);
}
fn print_rect(r1 : &Rectangle)
{
println!("Inside function {:?}",*r1);
//Rust doing auto-dereferncing ?
println!("Inside function {:?}",r1);
}
The println!() macro will (eventually) call the Rectangle's fmt() method (from std::fmt::Debug). Rust automatically dereferences if necessary when invoking method calls, so yes, you are seeing auto-deref here.