Skip to content

Commit 4f492b3

Browse files
committed
Add example for destructuring structs without match
1 parent 8ee9528 commit 4f492b3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/flow_control/match/destructuring/destructure_structures.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ fn main() {
2424
// this will give an error: pattern does not mention field `x`
2525
//Foo { y } => println!("y = {}", y),
2626
}
27+
28+
let faa = Foo { x: (1, 2), y: 3 };
29+
30+
// You do not need a match block to destructure structs:
31+
let Foo { x : x0, y: y0 } = faa;
32+
println!("Outside: x0 = {x0:?}, y0 = {y0}");
2733
}
2834
```
2935

0 commit comments

Comments
 (0)