Primitive Compound Datatypes in Rust Last Updated : 03 Dec, 2021 Comments Improve Suggest changes Like Article Like Report 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: ArraysTuplesThe 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. Example: Rust fn main() { // creating tuple let gfg: (&str, &str, &str) = ("Geeks", "For", "Geeks"); // accessing tuple data using positional argument println!("{} {} {}", gfg.0, gfg.1, gfg.2); // creating another tuple let article = ("geeksforgeeks", "kushwanthreddy", 14,12,2020); let (a,b,c,d,e) = article; // accessing tuple using variables println!("This article is written by {} at {} on {}/{}/{}", b,a,c,d,e); } Output: Geeks For Geeks This article is written by kushwanthreddy at geeksforgeeks on 14/12/2020The 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. Example: Rust fn main() { // creating array let gfg = ["Geeks", "For", "Geeks"]; // accessing array data using positional argument println!("{} {} {}", gfg[0], gfg[1], gfg[2]); } Output: 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. Comment More infoAdvertise with us Next Article Primitive Compound Datatypes in Rust K kushwanthreddy Follow Improve Article Tags : Programming Language Rust Rust data-types Similar Reads Scalar Datatypes in Rust All initialized variables use data-type during declaration to restrict the type of data to be stored. Therefore, we can say that data types are used to tell the variables the type of data they can store. In this article, we will specifically talk about the Scalar Data types in the Rust programming 3 min read Rust - Multiple Bounds In Rust, we have a concept of multiple bounds. Multiple bounds are defined under the Traits of Rust programming. Multiple bounds in Rust can be applied with a '+' operator and the types are separated using comma (,) For needing more than one bounds in Rust programs, we need to import use::std::fmt:: 2 min read Rust - Concept of Data Freezing Rust is a systems programming language. In Rust, there is a concept of freezing which states that whenever data is borrowed, the borrowed data is also frozen. This frozen data cannot be modified until the references get out of scope i.e. all the bindings go out of scope. Suppose in the given below e 1 min read Rust - Closure as an Input Parameter In Rust, Closures can be taken as input for the parameters. Closures are functions that wrap up functions for reusable purposes, which help capture variables in the enclosing environment. Closures are closed over when used in functions and for a single expression elimination ({ }) is used. The closu 3 min read Rust lifetime Constructor In Rust, we have a concept of a lifetime constructor that falls under the ownership category. Rust enforces a certain set of rules through its concept of ownership and lifetimes. In this article, we would be learning more about Lifetimes in Rust. In Rust, there are various regions that are present i 3 min read Like