I don’t understand why spawn_i is FnOnce, and not FnMut, since the argument is mutable.
The argument is not relevant, closure classifications is based on what they close over and how.
Here, the issue is that
f when called:
fis moved into it
spawn_iis called the first time, it creates the sub-closure and
fis moved into that
- the second time
spawn_iwould be called… it can’t be because there’s no
fto move into the sub-closure anymore
spawn_i can only be called once.
So you need
f to be reusable somehow e.g. store it in an
Arc, or make it a function pointer (
fn(usize) -> T) instead of a trait bound, or maybe play around with lifetimes.
CLICK HERE to find out more related problems solutions.