Tuple
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.
Syntax:
(“w3wiki”, 1, ‘geek’)
Below is the Rust program to implement Tuple:
// 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 0 index = {} ", gfg.0 );
// second value
println!("at 0 index = {} ", gfg.1 );
// third value
println!("at 0 index = {} ", gfg.2 );
// fourth value
println!("at 0 index = {} ", gfg.3 );
}
Output:
complete tuple = ("cp", "algo", "FAANG", "Data Structure")
at 0 index = cp
at 0 index = algo
at 0 index = FAANG
at 0 index = Data Structure
Introduction to Rust Programming Language
Rust is a blazing fast and memory-efficient static compiled language with a rich type system and ownership model. It can be used to power performance-critical services while guaranteeing memory-safety and thread-safety, empowering developers to debug at compile-time. In addition to that Rust has great documentation and a user-friendly compiler with top-end tools like integrated package managers and multi-editor with features like type inspection and auto-completion. Rust prevents all the crashes, and, interestingly, Rust is safe by default like JavaScript, Ruby, and Python. This is much more powerful than C/C++ because we cannot write the wrong parallel code you can never see fault in rust. It is very fast in representing a lot of programming paradigms very well.
But the question arises as there are already so many programming languages like Python, C++, Java, etc, then why the need for developing a new programming language? The answer to this is the other programming languages have a lot of control over the hardware that you are running, like, you can optimize it well, translate directly to assembly code, but it’s not very safe.
So rust provides us all the controls that we can have and all the levels of security that we can achieve.
Rust is using Rust which means that all the standard compiler libraries are written in rust; there is a bit of use of the C programming language but most of it is Rust. The big project of Rust is “servo”, It is a project to write out the totally parallel layout engine like Gecko in Firefox or WebKit in Safari.
Servo built the layout engine, something to render HTML from bottom to top.
Become a Rust Professional Learn the fundamentals of Rust programming, practice its applications in web and game development, and get ready for coding interviews with Educative’s interactive skill path Become a Rust Professional. Sign up at Educative.io with the code GEEKS10 to save 10% on your subscription
Table of Content
- Functions in Rust
- Concept of Ownership
- Concept of Borrowing
- Memory management in Rust
- Mutability
- Structure in Rust
- Tuple
- Rust Type System
- Advantages of Rust
- Disadvantages of Rust