How to convert Vec to HashMap

Convert a Vec of tuples to a HashMap using into_iter() and collect().

Use the into_iter() method on the vector and the collect() adapter to transform it into a HashMap.

use std::collections::HashMap;

let pairs = vec![("a", 1), ("b", 2)];
let map: HashMap<String, i32> = pairs.into_iter().collect();

This requires your vector to contain tuples where the first element is the key and the second is the value.