Start with the idea
Tuples group a fixed number of possibly different types and are read by position. Arrays hold one type with a length known at compile time, which is exactly what lets the compiler bounds-check them and reject an out-of-range index it can see.
The point in the example is a tuple: its first field is an i32 and its second is an f64. The fields are read as point.0 and point.1 because their positions, not names, identify them. The scores array is different: all four elements are u8, and the length 4 belongs to the type [u8; 4]. That makes scores[2] a predictable access to the third score. Before using an index, ask whether the index is a constant the compiler can reject or a runtime value that needs a check.
Tuples help when a few values belong together for a short journey through code. Arrays help when you have a fixed-size sequence of one kind of item.
Keep learning, for free
The rest of this lesson is waiting for you.
Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.
No payment details. Your account opens the complete Academy.