From 4f492b31ab87cb347590f6832929fdf83c210e67 Mon Sep 17 00:00:00 2001 From: Daniel Seemer Date: Tue, 23 May 2023 20:49:36 +0200 Subject: [PATCH] Add example for destructuring structs without match --- .../match/destructuring/destructure_structures.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/flow_control/match/destructuring/destructure_structures.md b/src/flow_control/match/destructuring/destructure_structures.md index 9e43b70c15..252104fefa 100644 --- a/src/flow_control/match/destructuring/destructure_structures.md +++ b/src/flow_control/match/destructuring/destructure_structures.md @@ -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}"); } ```