我想把我的if
箱换成match
箱
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"),
// }
}
它可以正常运行.但是,当我在代码中取消对代码片段的注释时,就会出现错误.
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 `}`
我不知道该如何修复它