I am having trouble getting a piece of code to work, as the errors I am getting are circular.
I start with the following code:
use std::collections::HashMap;
let mut hashm = HashMap::<Vec<&str>, &str>::new();
for i in v {
let s = i.split('\t').collect::<Vec<&str>>();
let j = s[0]
.replace(&['{', '}'][..], "") // replace multiple at once; https://users.rust-lang.org/t/24554/2
.split(", ")
.collect::<Vec<&str>>();
let k = s[1];
hashm.insert(j, k);
}
The error I get says that s[0]
creates a temporary which is freed while still in use...
hashm.insert(j, k);
- borrow later used here
So I change hashm.insert(j, k) to hashm.insert(&j, k) and HashMap::<Vec<&str>, &str>::new(); to HashMap::<&Vec<&str>, &str>::new();, but then I get the same error, as well as this:
hashm.insert(&j, k);
^^ borrowed value does not live long enough
How can I rectify this?