mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-25 05:29:41 +00:00
fix typos
This commit is contained in:
@ -65,7 +65,7 @@ fn main() {
|
||||
|
||||
fn show_message(msg: Message) {
|
||||
match msg {
|
||||
__ => { // matches Message::Move
|
||||
__ => { // match Message::Move
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 3);
|
||||
},
|
||||
@ -166,11 +166,11 @@ fn main() {
|
||||
|
||||
// remove the codes below, using `match` instead
|
||||
if let Foo::Bar = a {
|
||||
println!("matches foo::bar")
|
||||
println!("match foo::bar")
|
||||
} else if let Foo::Baz = a {
|
||||
println!("matches foo::baz")
|
||||
println!("match foo::baz")
|
||||
} else {
|
||||
println!("matches others")
|
||||
println!("match others")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -1 +0,0 @@
|
||||
# Option destructing
|
@ -1 +1,23 @@
|
||||
# Patterns
|
||||
|
||||
🌟🌟 Using `|` to match several values.
|
||||
```rust,editable
|
||||
|
||||
fn main() {}
|
||||
fn match_number(n: i32) {
|
||||
match n {
|
||||
// match a single value
|
||||
1 => println!("One!"),
|
||||
// fill in the blank with `|`, DON'T use `..` ofr `..=`
|
||||
__ => println!("match 2 -> 5"),
|
||||
// match an inclusive range
|
||||
6..=10 => {
|
||||
println!("match 6 -> 10")
|
||||
},
|
||||
_ => {
|
||||
println!("match 11 -> +infinite")
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user