Destructuring
Structs, enums, tuples.
What Is Destructuring?
Destructuring breaks a compound value apart into its pieces using a pattern. It works with tuples, structs, enums, arrays, and more.
Destructuring Tuples
Bind each element of a tuple to its own variable in a single let.
fn main() {
let point = (3, 7);
let (x, y) = point;
println!("x = {x}, y = {y}");
}All lessons in this course
- match Deep Dive
- if let and while let
- Binding with @
- Destructuring