add one exercise in patterns.md

This commit is contained in:
sunface
2022-03-11 15:45:03 +08:00
parent 7bc4cf757b
commit 553f7b1648
3 changed files with 43 additions and 0 deletions

View File

@@ -101,4 +101,19 @@ fn main() {
}
```
6. 🌟🌟 Using pattern `&mut V` to match a mutable reference needs you to be very careful due to `V` being a value after matching
```rust,editable
// FIX the error with least changing
// DON'T remove any code line
fn main() {
let mut v = String::from("hello,");
let r = &mut v;
match r {
&mut value => value.push_str(" world!")
}
}
````
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it