Stuck on a Rustlings problem (standard_library_types/iterators5.rs)

I'm working through the Rustlings set of exercises. Doing overall OK so far, but I'm completely stuck on the second part of standard_library_types/iterators5.rs, in which I'm supposed to write a function that iterates over a collections of maps.

My code tries to reuse the same iterator-based function that I wrote for the first half of this exercise. The code for these two functions is:

fn count_iterator(map: &HashMap<String, Progress>, value: Progress) -> usize {
    map.values().into_iter().filter(|&v| *v == value).count()
}

fn count_collection_iterator(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
    collection
        .iter()
        .map(|m| count_iterator(m, value))
        .fold(0, |acc, n| acc + n)
}

However, the second function results in a compilation error:

! Compiling of exercises/standard_library_types/iterators5.rs failed! Please try again. Here's the output:
error[E0507]: cannot move out of `value`, a captured variable in an `FnMut` closure
  --> exercises/standard_library_types/iterators5.rs:55:36
   |
52 | fn count_collection_iterator(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
   |                                                                        ----- captured outer variable
...
55 |         .map(|m| count_iterator(m, value))
   |                                    ^^^^^ move occurs because `value` has type `Progress`, which does not implement the `Copy` trait

error: aborting due to previous error

I've been through all the docs I can find, and I cannot figure out how to pass the value parameter into the calls to the fn being called within map().

Randy

Hi, have you try implementing count_iterator like this:

fn count_iterator(map: &HashMap<String, Progress>, value: &Progress) -> usize {
    //                                                    ^ borrow Progress
    map.values().into_iter().filter(|&v| v == value).count()
}

and then in your count_collection_iterator function, pass a borrow of value instead of move into the count_iterator function

fn count_collection_iterator(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
    collection
        .iter()
        .map(|m| count_iterator(m, &value))
        //                         ^ pass a borrow
        .fold(0, |acc, n| acc + n)
}

Here is the playground link.

I considered that at first, but the prelude comment in the file (iterators5.rs) said that it was only necessary to change the two functions (count_iterator and count_collection_iterator). If I changed the signature of count_iterator, I would then have to change the tests later in the file as well.

It doesn't seems like the rustling intended to reuse the count_iterator() function there. There's no way to duplicate the Progress and you can't pass it by reference without modify the surrounding code.