Topic
Tuples
A tuple groups values of different types together in a single variable. Unlike arrays, each element can be a different type. You access elements by position using dot notation, or unpack everything at once with destructuring. Tuples are useful any time you need to pass or return a few related values without defining a full struct.
Quick Reference
ConceptWhat it means
TupleA single variable that holds multiple values of different types grouped together.
(i32, &str)Tuple type signature: parentheses with the types inside, separated by commas.
t.0Tuple indexing: the first element is at index 0, the second at 1, and so on.
DestructuringPulling a tuple apart into separate variables with let (a, b) = t;
Nested tupleA tuple inside another tuple, like (u8, (i32, i32)).
TermWhat it meansWhen you use it
TupleA single variable holding multiple values of different typesWhen grouping a few related values without defining a struct
(i32, &str)Tuple type: parentheses with types inside, separated by commasWhen declaring or annotating a tuple variable
t.0Tuple indexing: first element is at 0, second at 1, and so onWhen extracting one specific element by position
DestructuringPulling a tuple apart into separate variables with let (a, b) = t;When you need all elements as separate named variables
Nested tupleA tuple inside another tuple, like (u8, (i32, i32))When grouping within a group, like (address, (balance, nonce))