Users may not have control over the max watches limit of the recommended_watcher. In this case, it is desirable to fallback to the PollWatcher implementation which is x-platform as far as I can tell and shouldn't experience the same restriction.
To check if the watcher limit has been reached, we create a NamedTempFile using tempfile and check the result of watcher.watch on the recommended_watcher.
I've also removed some unwraps which were causing problems. Some are replaced with match blocks, others with bindings. I can't see any immediate problems from this, but it might be worth checking it out.
The checking code might be better off in a separate function which returns a Box<dyn Watcher> so can do that if you'd prefer.
Users may not have control over the max watches limit of the
recommended_watcher
. In this case, it is desirable to fallback to thePollWatcher
implementation which is x-platform as far as I can tell and shouldn't experience the same restriction.To check if the watcher limit has been reached, we create a
NamedTempFile
usingtempfile
and check the result ofwatcher.watch
on therecommended_watcher
.I've also removed some unwraps which were causing problems. Some are replaced with match blocks, others with bindings. I can't see any immediate problems from this, but it might be worth checking it out.
The checking code might be better off in a separate function which returns a
Box<dyn Watcher>
so can do that if you'd prefer.