mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-23 20:49:41 +00:00
add destructuring assignments
This commit is contained in:
@ -116,4 +116,23 @@ fn main() {
|
||||
assert_eq!(x, 3);
|
||||
assert_eq!(y, 2);
|
||||
}
|
||||
```
|
||||
|
||||
### Destructuring assignments
|
||||
🌟🌟 fix the code with two ways:
|
||||
|
||||
- Shadowing with adding `let`
|
||||
- make types compatible
|
||||
|
||||
|
||||
> Note: the feature `Destructuring assignments` need 1.59 or higher Rust version
|
||||
|
||||
```rust,editable
|
||||
|
||||
fn main() {
|
||||
let (mut x, mut y) = (1.0, 2.0);
|
||||
(x,y) = (3, 4);
|
||||
|
||||
assert_eq!([x,y],[3, 4]);
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user