Q:

Rust program to implement destructive assignment with tuple

belongs to collection: Rust Tuples Programs

0

In this program, we will implement destructive assignments of tuple members into different variables and print them.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to implement destructive assignment with tuple is given below. The given program is compiled and executed successfully.

// Rust program to implement 
// destructive assignment 
// with tuple

fn PrintEmployee(emp:(i32,&str,u8))
{
   let (id,name,age) = emp;
   println!("Employee Information: ");
   println!("\tEmployee Id  : {}",id);
   println!("\tEmployee Name: {}",name);
   println!("\tEmployee Age : {}",age); 
}

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

Output:

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

Explanation:

In the above program, we created two functions PrintEmployee() and main(). The PrintEmployee() function accept tuple as a parameter and perform the destructive assignment of tuple members into a different variable.

In the main() function, we created a tuple MyTuple that contains employee information. Then we called PrintEmployee() function and printed the result.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

<< Rust program to pass a tuple as a parameter...