Rust - Tuple Last Updated : 18 Oct, 2022 Comments Improve Suggest changes Like Article Like Report 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 the index to get the value of a tuple, and we also can not iterate over a tuple using for loop. Tuples in Rust are defined using small brackets as shown below : Syntax: ("geeksforgeeks", 1, 'geek') It is important to note that tuples are a sequence in Rust. This means its elements can be accessed by the position which is also known as tuple indexing. Example 1: Below is the rust program to get values in a tuple. Rust // Rust program to get value from tuple // using index fn main() { let gfg = ("cp", "algo", "FAANG", "Data Structure"); // complete tuple println!("complete tuple = {:?} ", gfg ); // first value println!("at 0th index = {} ", gfg.0 ); // second value println!("at 1st index = {} ", gfg.1 ); // third value println!("at 2nd index = {} ", gfg.2 ); // fourth value println!("at 3rd index = {} ", gfg.3 ); } Output : complete tuple = ("cp", "algo", "FAANG", "Data Structure") at 0th index = cp at 1st index = algo at 2nd index = FAANG at 3rd index = Data Structure Example 2: Here we will use strings and integers both in tuples. Rust fn main() { // tuple with different types of values let gfg = ("cp", 10, "FAANG", 20); println!("complete tuple = {:?} ", gfg ); println!("at 0th index = {} ", gfg.0 ); println!("at 1st index = {} ", gfg.1 ); println!("at 2nd index = {} ", gfg.2 ); println!("at 3rd index = {} ", gfg.3 ); } Output : complete tuple = ("cp", 10, "FAANG", 20) at 0th index = cp at 1st index = 10 at 2nd index = FAANG at 3rd index = 20 Comment More infoAdvertise with us Next Article Rust - Supertraits A agrajat112 Follow Improve Article Tags : Rust Rust custom-types Similar Reads Rust - Slices Slice is a data type that does not have ownership. Slice references a contiguous memory allocation rather than the whole collection. Slices are also present in Python which is similar to slice here in Rust. Slice is used when you do not want the complete collection, or you want some part of it. Sli 3 min read Rust - Supertraits In Rust, we have a concept of super traits. Rust being a modern systems-based programming language focuses mainly on the speed, safe and concurrent aspects of programming.  Supertraits in Rust are traits that require implementation for conversion of specific types for implementing specific traits. 2 min read Rust - Result Type In Rust, we have a result-type operator that is used for error-handling operations with the result-type operator. The Result type is wrapped in an enum that has two values - Ok and Err. Ok (T) denotes success while Err(E) is used for representing errors and error values (if present). While working 3 min read Rust - Traits A trait tells the Rust compiler about functionality a particular type has and can share with other types. Traits are an abstract definition of shared behavior amongst different types. So, we can say that traits are to Rust what interfaces are to Java or abstract classes are to C++. A trait method is 8 min read Rust - While Loop Loops in Rust come into use when we need to repeatedly execute a block of statements. Loops are also useful when we need to iterate over a collection of items. In Rust, we have various kinds of loops, including loops, while loops, and for loops. The while loop is the most common loop in Rust. The lo 3 min read Rust - Strings String data type is a very important part of any programming language. Rust handles strings a bit differently from other languages.  The String data type in Rust is of two types: String Literal (&str)String Object (String)String LiteralString Literal or &str are called 'string slices', whic 2 min read Like