rustlings icon indicating copy to clipboard operation
rustlings copied to clipboard

options3 ref vs &

Open eyyyyyyy3 opened this issue 1 year ago • 0 comments

Why is this way of solving the challenge:

`fn main() { let y: Option<Point> = Some(Point { x: 100, y: 200 });

match y {
    Some(ref p) => println!("Co-ordinates are {},{} ", p.x, p.y),
    _ => panic!("no match!"),
}
y; // Fix without deleting this line.

}`

more preferred than this one: `fn main() { let y: Option<Point> = Some(Point { x: 100, y: 200 });

match &y {
    Some(p) => println!("Co-ordinates are {},{} ", p.x, p.y),
    _ => panic!("no match!"),
}
y; // Fix without deleting this line.

}`

eyyyyyyy3 avatar Oct 14 '23 14:10 eyyyyyyy3