How do I insert a tuple value into HashMap using `insert()`?

Budding Rustacean here. I'm trying to insert a (i32, (usize, usize)) pair into the last hashmap which exists in my vector of hashmaps using the following code:

let mut boards: Vec<HashMap<i32, (usize, usize)>>;
for line in file_it.lines() { // file_it is a BufReader file iterator
    if line.unwrap().is_empty() {
        for row in 0..5 {
            match file_it.read_line(&mut buf) {
                Ok(n) => {
                    let curr_row: Vec<i32> = buf
                                    .map(|num| num.trim().parse::<i32>().unwrap())
                    for (col, num) in curr_row.iter().enumerate() {
                            .insert(num, (row, col));
                Err(e) => println!("Error reading bingo board {}", boards.len()),

However, I get the following error:

error[E0061]: this function takes 1 argument but 2 arguments were supplied
    --> src/
29   | ...                   .insert(num, (row, col));
     |                        ^^^^^^ ---  ---------- supplied 2 arguments
     |                        |
     |                        expected 1 argument

How do I fix this?

You are calling Option::insert, not HashMap::insert. boards.last().unwrap().insert(num, (row, col)).

1 Like

That worked. Thank you @sfackler !

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.