Skip to content

Commit

Permalink
Merge pull request #1709 from Phaiax/px/destructure-structs
Browse files Browse the repository at this point in the history
Add example for destructuring structs without match
  • Loading branch information
marioidival authored May 24, 2023
2 parents 8ee9528 + 4f492b3 commit db8e52a
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 db8e52a

Please sign in to comment.