Skip to content

Commit 4c2b24f

Browse files
authored
Merge pull request #1787 from arghav/structs/nested-destructuring-example
nested destructure example for structs
2 parents 70e0f0a + eef6545 commit 4c2b24f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/flow_control/match/destructuring/destructure_structures.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ fn main() {
3030
// You do not need a match block to destructure structs:
3131
let Foo { x : x0, y: y0 } = faa;
3232
println!("Outside: x0 = {x0:?}, y0 = {y0}");
33+
34+
// Destructuring works with nested structs as well:
35+
struct Bar {
36+
foo: Foo,
37+
}
38+
39+
let bar = Bar { foo: faa };
40+
let Bar { foo: Foo { x: nested_x, y: nested_y } } = bar;
41+
println!("Nested: nested_x = {nested_x:?}, nested_y = {nested_y:?}");
3342
}
3443
```
3544

0 commit comments

Comments
 (0)