I needed to find the unique count of each item in a list, but the only way I could get it to work was to clone the list inside a for loop, which is something I want to learn how to avoid. Simplified example:
fn main() {
let v: Vec<i32> = vec![1, 2, 2, 3, 4, 4, 5];
for i in v.clone() {
let _count = v.clone().into_iter().filter(|j| *j == i).count();
}
}
Can the inner clone be avoided while keeping the logic intact? (and without just using something that clones under-the-hood).