Skip to content

Commit

Permalink
Add example for destructuring structs without match
Browse files Browse the repository at this point in the history
  • Loading branch information
Phaiax committed May 23, 2023
1 parent 8ee9528 commit 4f492b3
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ fn main() {
// this will give an error: pattern does not mention field `x`
//Foo { y } => println!("y = {}", y),
}
let faa = Foo { x: (1, 2), y: 3 };
// You do not need a match block to destructure structs:
let Foo { x : x0, y: y0 } = faa;
println!("Outside: x0 = {x0:?}, y0 = {y0}");
}
```

Expand Down

0 comments on commit 4f492b3

Please sign in to comment.