I am pretty new to rust, so I have a bit of trouble with the borrow checker. I have a json object which is a vector of the form:
Vec<(String, Option<char>, String)>
.
I want to be able to convert this vector into a hash map in order to allow for quick access of each element. Originally, each tuple was unique, and the user would pass a pair of a string and a char, so I had a hashmap of which was of the form HashMap<(String, Option<char>), String>
. The conversion function was just an iteration over the original vector passed as a json object like so:
let new_transition_function: Vec<(String, Option<char>, String)> = origin
.transition_function
.iter()
.map(|(x, y, z)| ((x.to_owned(), y.to_owned()), z.to_owned()))
.collect();
However, when the third element is non-unique, the value is jsut replaced in the hashmap, when I need to keep each value. How can I most efficiently and idiomatically transform the old vector of Vec<(String, Option<char>, String)>
to a HashMap<(String, Option<char>), Vec<String>)>
?