I am trying to learn more about ownership. Here is some code that doesn't work because collect
doesn't let you get a &mut String
:
fn search(word: &str, data: &mut Vec<String>) {
data = data
.iter()
.filter(|x| x.contains(word))
.collect::<&mut Vec<String>>();
}
I think I could just return a cloned version, but is this the only/preferred way to do it?