Rust tuple - fixed-sizes, mixed, ordered collection
-
tuple
-
parenthesis
-
()
-
Each value can be any type. (heterogeneous)
-
The types and the number of elements are fixed at creation.
-
In this example the types are deducted from the values.
-
It is ordered.
-
We can access the individual elements using their index and the dot-notation.
-
The content can be changed only if the definition uses
mut
.
fn main() { let things = (11, '2', String::from("three")); println!("{}", things.0); println!("{}", things.1); println!("{}", things.2); println!("{:?}", things); }
11
2
three
(11, '2', "three")