0Pricing
Learn Rust Coding · Lesson

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

  1. match Deep Dive
  2. if let and while let
  3. Binding with @
  4. Destructuring
← Back to Learn Rust Coding