options3 ref vs &
#2029
-
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.
} |
Beta Was this translation helpful? Give feedback.
Answered by
mo8it
Jul 7, 2024
Replies: 2 comments 1 reply
-
I'm also interesed for feedback. I'm learning Rust and my first though was to |
Beta Was this translation helpful? Give feedback.
0 replies
-
What do you mean with "more preferred"? Is it because the compiler suggests it? Personally, I prefer the second solution with |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
mo8it
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What do you mean with "more preferred"? Is it because the compiler suggests it?
Personally, I prefer the second solution with
&
overref
.ref
is rarely used in the Rust code that I read until now.