The following code works
#[derive(Debug)]
struct Rectangle {
width: u32,
height: u32
}
fn area(shape: &Rectangle) -> u32 {
let Rectangle{width, height} = shape;
width * height
}
fn main() {
let rec1 = Rectangle {width: 5, height: 10};
println!("Area {}", area(&rec1));
println!("Rec {:?}", rec1);
}
But replacing the reference to struct &Shape with dereference reference *&Shape also works (e.g let Rectangle{width, height} = shape; --> let Rectangle{width, height} = *shape;).
I have no idea why both work, is there some implicit dereferencing when destructing? I though &Shape reference only points to where Shape is in memory, whereas *&Shape is Shape itself. width and height are properties of struct Rectangle rather than the reference &Rectangle.