What Is the Difference Between a Struct and a Tuple in Rust?

Structs are named types with labeled fields for complex data, while tuples are anonymous, fixed-length collections accessed by index.

A struct is a named, custom data type with labeled fields, while a tuple is an anonymous, fixed-length collection of values accessed by index. Use structs when you need to group related data with semantic meaning and use tuples for temporary, heterogeneous data without the overhead of naming fields.

// Struct: Named fields, semantic meaning
struct Point {
    x: i32,
    y: i32,
}
let p = Point { x: 10, y: 20 };
println!("{}", p.x); // Access by name

// Tuple: Anonymous, fixed order
let t = (10, 20);
println!("{}", t.0); // Access by index