I’m trying to develop a small application that reads a directory and then does some processing for each file. I’d thought on having a number of threads doing that job, and for that, I’ve thought on creating a Vec with all the files in the directory and then each thread would pop one file and analyze it. When finished, it would analyze another one. All the results should go to a shared struct. I’ve managed to create this code (simplified here for debugging purposes):
And I get a lifetime issue. The thing is that I would like the unit analysis to only receive a Mutex, not an Arc, but that gives type errors: seems I cannot get a
Mutex<Result> from a
&mut Result easily.
How can I fix it?