structs

Similarly, a struct can be destructured as shown:

1. fn main() {
2. struct Foo { x: (u32, u32), y: u32 }

4. // destructure members of the struct
5. let foo = Foo { x: (1, 2), y: 3 };
6. let Foo { x: (a, b), y } = foo;

8. println!("a = {}, b = {},  y = {} ", a, b, y);

10. // you can destructure structs and rename the variables,
11. // the order is not important

13. let Foo { y: i, x: j } = foo;
14. println!("i = {:?}, j = {:?}", i, j);

16. // and you can also ignore some variables:
17. let Foo { y, .. } = foo;
18. println!("y = {}", y);

20. // this will give an error: pattern does not mention field `x`
21. // let Foo { y } = foo;
22. }

See also:

Structs, The ref pattern