add destructuring assignments

This commit is contained in:
sunface
2022-02-25 11:18:27 +08:00
parent 1371c86e3f
commit f393232de1
10 changed files with 926 additions and 5 deletions

View File

@@ -117,4 +117,22 @@ fn main() {
assert_eq!(x, 3);
assert_eq!(y, 2);
}
```
### 解构式赋值
🌟🌟 使用两种方式解决问题:
- 通过变量遮蔽: 添加 `let`
- 令类型兼容
> Note: 解构式赋值只能在 Rust 1.59 或者更高版本中使用
```rust,editable
fn main() {
let (mut x, mut y) = (1.0, 2.0);
(x,y) = (3, 4);
assert_eq!([x,y],[3, 4]);
}
```