Link Search Menu Expand Document

Solution 2: Declare a Tuple

  • Solution:

fn test() {
    // define a tuple
    let persons = ("Alex",21, "Abe", 22, "Anna", 23);
    // print the values of tuple
    print!("{}:{}, {}:{}, {}:{}", persons.0, persons.1, persons.2, persons.3, persons.4, persons.5);
}


Output-


Alex:21, Abe:22, Anna:23

Explanation

  • On line 3, a tuple, persons, of size 6 is defined with values.
  • On line 5, print the value of the persons elements using the dot operator notation (.) accessed using placeholder {} for each value within the print!() macro.