mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-02-24 21:32:15 +08:00
20 lines
481 B
Rust
20 lines
481 B
Rust
|
fn main() {
|
||
|
// ANCHOR: here
|
||
|
enum Message {
|
||
|
Hello { id: i32 },
|
||
|
}
|
||
|
|
||
|
let msg = Message::Hello { id: 5 };
|
||
|
|
||
|
match msg {
|
||
|
Message::Hello {
|
||
|
id: id_variable @ 3..=7,
|
||
|
} => println!("Found an id in range: {}", id_variable),
|
||
|
Message::Hello { id: 10..=12 } => {
|
||
|
println!("Found an id in another range")
|
||
|
}
|
||
|
Message::Hello { id } => println!("Found some other id: {}", id),
|
||
|
}
|
||
|
// ANCHOR_END: here
|
||
|
}
|