I would like to replace my if
case with match
case
struct Point {
x: i32,
}
fn main() {
let p = Point { x: 0 };
let q = Point { x: 0 };
if p.x == q.x {
println!("p and q have same x: {0}", p.x);
} else {
println!("p and q doesn't have same x value");
}
// match p.x {
// q.x => println!("p and q have same x: {0}", p.x),
// _ => println!("On neither axis"),
// }
}
which run normally. However when I uncomment my code snippet in the code an error would occur.
error: expected one of `,`, `=>`, `@`, `if`, `|`, or `}`, found `.`
--> src/main.rs:16:10
|
16 | q.x => println!("p and q have same x: {0}", p.x),
| ^ expected one of `,`, `=>`, `@`, `if`, `|`, or `}`
Not sure how to fix it