Im a noob in rust and i try to pass the app param to my event_handler function, but i have the following error and i don't know how to solve it..
(dyn for<'a> FnOnce(&'a mut tauri::App) -> Result<(), Box<(dyn std::error::Error + 'static)>> + Send + 'static)` cannot be shared between threads safely
the trait `Sync` is not implemented for `(dyn for<'a> FnOnce(&'a mut tauri::App) -> Result<(), Box<(dyn std::error::Error + 'static)>> + Send + 'static)`, which is required by `{closure@src\app\src-tauri\src\file_watcher.rs:23:41: 23:48}: EventHandler
impl<'a> ExtensionWatcher<'a> {
pub fn new(app: &'a App) -> notify::Result<Self> {
let mut watcher =
notify::recommended_watcher(|event| Self::event_handler(event, app)).unwrap();
// Start to watch the extension directory
Self::watch(&mut watcher, EXTENSION_DIRECTORY)?;
Ok(Self { app, watcher })
}
fn event_handler(event: notify::Result<notify::Event>, app: &'a App) {
match event {
Ok(event) => {
if event.kind == EventKind::Modify(ModifyKind::Any) {
for path in &event.paths {
if path.extension() == Some(OsStr::new("dll")) {
}
}
}
println!("{:?}", event)
}
Err(e) => {
println!("{:?}", e)
}
}
}
pub fn watch(watcher: &mut notify::RecommendedWatcher, path: &str) -> notify::Result<()> {
watcher.watch(Path::new(path), notify::RecursiveMode::Recursive)?;
Ok(())
}
}