Skip to content

Commit

Permalink
Merge pull request #1787 from arghav/structs/nested-destructuring-exa…
Browse files Browse the repository at this point in the history
…mple

nested destructure example for structs
  • Loading branch information
marioidival authored Dec 18, 2023
2 parents 70e0f0a + eef6545 commit 4c2b24f
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ fn main() {
// You do not need a match block to destructure structs:
let Foo { x : x0, y: y0 } = faa;
println!("Outside: x0 = {x0:?}, y0 = {y0}");
// Destructuring works with nested structs as well:
struct Bar {
foo: Foo,
}
let bar = Bar { foo: faa };
let Bar { foo: Foo { x: nested_x, y: nested_y } } = bar;
println!("Nested: nested_x = {nested_x:?}, nested_y = {nested_y:?}");
}
```

Expand Down

0 comments on commit 4c2b24f

Please sign in to comment.