Compiling playground v0.0.1 (/playground)
error[E0502]: cannot borrow `watcher` as immutable because it is also borrowed as mutable
--> src/main.rs:27:5
|
22 | let mut clsr = || {
| -- mutable borrow occurs here
23 | watcher.trng.next_u32();
| ------------ first borrow occurs due to use of `watcher.trng` in closure
...
27 | watcher.watch(&mut clsr);
| ^^^^^^^^^^^^^^---------^
| | |
| | mutable borrow later used here
| immutable borrow occurs here
For more information about this error, try `rustc --explain E0502`.
error: could not compile `playground` (bin "playground") due to previous error
I want to create a filewatcher. 'pat' vector contains patterns to watch. trng is notify filewatcher. I am writing act method for watching/unwatching according a flag in single method, otherwise i have to write two method with duplicated code.
I already know about lifetimes and tried several workarounds but none worked and I dont wanna use 'Clone' or 'Copy'
I hope its clear enough
note: rand is used due to rust playground doesnt allow notify
You probably could also make your callback return a bool and when it is true you notify. Don't know if this is how your notification logic works though. That way you can keep your notifier hidden from the closure and make your interface even better IMO: