mirror of
https://github.com/gnu4cn/rust-lang-zh_CN.git
synced 2026-08-22 22:23:28 +08:00
reorganized the directories
This commit is contained in:
8
projects/pattern_syntax_demo/Cargo.toml
Normal file
8
projects/pattern_syntax_demo/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "pattern_syntax_demo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
17
projects/pattern_syntax_demo/src/main.rs
Normal file
17
projects/pattern_syntax_demo/src/main.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
fn main() {
|
||||
enum Message {
|
||||
Hello { id: u32 },
|
||||
}
|
||||
|
||||
let msg = Message::Hello { id: 5 };
|
||||
|
||||
match msg {
|
||||
Message::Hello {
|
||||
id: id_variable @ 3..=7,
|
||||
} => println! ("找到位于范围内的一个 id: {}", id_variable),
|
||||
Message::Hello { id: 10..=12 } => {
|
||||
println! ("找到位于另一范围的一个 {}", id);
|
||||
},
|
||||
Message::Hello { id } => println! ("找到别的一个 id: {}", id),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user