ADVERTISEMENT
ADVERTISEMENT

Rust program to access members of tuple one by one

Rust | Tuple Example: Write a program to access members of tuple one by one.
Submitted by Nidhi, on October 18, 2021

Problem Solution:

In this program, we will create a tuple to store employee information, and then we will print employee information by accessing members one by one.

Program/Source Code:

The source code to access members of tuple one by one is given below. The given program is compiled and executed successfully.

// Rust program to access members of tuple 
// one by one

fn main() {
   let MyTuple:(i32,&str,u8) = (101,"Dhairya Pratap",25);

   println!("Employee Information: ");
   println!("\tEmployee Id  : {}",MyTuple.0);
   println!("\tEmployee Name: {}",MyTuple.1);
   println!("\tEmployee Age : {}",MyTuple.2);
}

Output:

Employee Information: 
        Employee Id  : 101
        Employee Name: Dhairya Pratap
        Employee Age : 25

Explanation:

Here, we created a tuple MyTuple that contains employee information. Then we accessed the members of MyTuple and printed the employee information.

Rust Tuples Programs »



ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.