Primitive Compound Datatypes in Rust
Rust programming language has a concept of compound data types which collections that can group multiple types into one. In simple words, compound Datatypes are data structures that can hold multiple data elements in a single variable (or) reference. There are two primitive compound types in Rust:
The Tuple Type:
A tuple in Rust is a finite heterogeneous compound data type, meaning it can store more than one value at once. In tuples there is no inbuilt method to add elements into a tuple. We can use index to get the value of a tuple, and we also can not iterate over a tuple using for loop, unlike arrays which are mutable, meaning once declared they cannot grow or shrink.
Geeks For Geeks This article is written by kushwanthreddy at geeksforgeeks on 14/12/2020
The Array Type:
Arrays are the same as tuples but the difference is that Arrays can have multiple values of the same data type whereas tuples can have multiple values of multiple data types. Arrays in Rust are different from arrays in some other languages because arrays in Rust have a fixed length, like tuples. the array are written as a comma-separated list inside square brackets.
Geeks For Geeks
In many low-level languages when you provide an incorrect index, invalid memory can be accessed. Rust protects you against this kind of error by immediately exiting instead of allowing memory access and continuing.