[Rust] Accessing specific values in a tuple by index

fn main() {
    let cat = ("Furry McFurson", 3.5);
    let (name, age) = cat;

    println!("{} is {} years old.", name, age);
}

 

Example 2:

#[test]
fn indexing_tuple() {
    let numbers = (1, 2, 3);
    let second = numbers.1;

    assert_eq!(2, second,
        "This is not the 2nd number in the tuple!")
}

 

posted @ 2024-02-23 19:04  Zhentiw  阅读(2)  评论(0编辑  收藏  举报