beginnerCompound Types
Tuple Destructuring
Create and destructure tuples in Rust.
Tuple Destructuring
Create and destructure tuples in Rust.
Difficulty
Beginner
Code
rust
fn main() {
let point = (10, 20, 30);
let (x, y, z) = point;
println!("x={}, y={}, z={}", x, y, z);
let (first, ..) = point;
println!("first: {}", first);
println!("access by index: {}", point.1);
}Explanation
Tuples group different types. Destructuring extracts values into variables.
Key Concepts
- Read the code carefully and understand the data flow
- Try modifying the example to see how it changes behavior
- Run this code in the Rust Playground
Related Topics
Browse more examples in the compound-types category to build a complete understanding of this topic.