Rust - Tuple Flashcards

1
Q

Describe Tuple

A

Tuple is a compound data type.
It can store different data types.
It has a fixed length; once decleared it cannot grow or shrink in size

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

An example of a tuple and print it

A

let personal_info : (String, u32, u64) = (String::from(“Ibekwe Prince”), 19, 177);

println!(Name: {:?}, personal_info.0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Pass a tuple as a parameter to a function

A

let b : (i32, bool, f64) = (110, true, 10.9);

print(b);

fn print(tup: (i32, bool, f64)){

//
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to destruct a tupe.

A

let b:(i32,bool,f64) = (30,true,7.9);

let (age, is_male, cg)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly