I’m trying to store a list of strings under a string key, but seem to be unable to because of this error.
Here’s a simpler version of the code causing it:
use std::collections::HashMap;
use std::vec::Vec;
struct Test<'a> {
tests: HashMap<String, &'a mut Vec<String>>,
}
impl<'a> Test<'a> {
pub fn add(&mut self, a: &str, b: &[String]) {
for c in b {
let string_a = String::from(a.to_owned());
match self.tests.get(&string_a) {
Some(items) => {
items.push(String::from(c.to_owned()));
self.tests.insert(string_a, &mut items);
},
_ => {
let items = Vec::new();
items.push(String::from(a.to_owned()));
self.tests.insert(string_a, &mut items);
}
}
}
}
}
fn main() {
let test = Test {
tests: HashMap::new(),
};
test.add(&"a", &[String::from("b")]);
}