Ownership and borrowing error

let element_frequency : Vec<(&String, usize)> = duplicate_uniques.into_iter().map(|x| (&x, get_frequency(&uniques, x))).collect();
I used the variable x many times in code so it is showing the error as

let element_frequency : Vec<(&String, usize)> = duplicate_uniques.into_iter().map(|x| (&x, get_frequency(&uniques, x))).collect();
| - -----------------------------^--
| | || |
| | || move out of x occurs here
| | |borrow of x occurs here
| | returning this value requires that x is borrowed for '1
| return type of closure is (&'1 std::string::String, usize)

Could you please help me to fix that error

Please read the pinned post about code formatting, and edit your post accordingly.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.