How to declare initialize and print vector of pairs (list of tuples) in Rust

1 Answer

0 votes
fn print(vec: &Vec<(i32, i32)>) {
    for &(first, second) in vec {
        println!("{}, {}", first, second);
    }
}

fn main() {
    let vec = vec![(5, 8), (4, 6), (-1, 9), (3, 7)];
    
    print(&vec);
}

 
 
/*
run:

5, 8
4, 6
-1, 9
3, 7

*/

 



answered Aug 25, 2024 by avibootz

Related questions

...