mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-23 04:29:41 +00:00
add one exercise in patterns.md
This commit is contained in:
@ -97,4 +97,19 @@ fn main() {
|
||||
}
|
||||
```
|
||||
|
||||
6. 🌟🌟 使用模式 `&mut V` 去匹配一个可变引用时,你需要格外小心,因为匹配出来的 `V` 是一个值,而不是可变引用
|
||||
```rust,editable
|
||||
|
||||
// 修复错误,尽量少地修改代码
|
||||
// 不要移除任何代码行
|
||||
fn main() {
|
||||
let mut v = String::from("hello,");
|
||||
let r = &mut v;
|
||||
|
||||
match r {
|
||||
&mut value => value.push_str(" world!")
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)
|
Reference in New Issue
Block a user