trpl-zh-cn/listings/ch18-patterns-and-matching/listing-18-14/src/main.rs
2023-01-16 17:34:52 +08:00

19 lines
364 B
Rust
Executable File

struct Point {
x: i32,
y: i32,
}
// ANCHOR: here
fn main() {
let p = Point { x: 0, y: 7 };
match p {
Point { x, y: 0 } => println!("On the x axis at {x}"),
Point { x: 0, y } => println!("On the y axis at {y}"),
Point { x, y } => {
println!("On neither axis: ({x}, {y})");
}
}
}
// ANCHOR_END: here