I'm trying to do hot reloading when a file changes, but I'm getting this error:
expected a closure that implements the Fn trait, but this closure only implements FnMut
this closure implements FnMut, not Fn
Seems to be unhappy with the closure I'm passing to the new_immediate function from this library:
notify = { version = "5.0.0-pre.4", features = ["serde"] }
My code:
use announcer::messages::{load_config, save_config, Config, Message};
use notify::{
event::ModifyKind, Error, Event, EventFn, EventKind, RecommendedWatcher, RecursiveMode, Watcher,
};
use tide::{http, Body, Response};
const CONFIG_PATH: &str = "config.json";
#[async_std::main]
async fn main() -> tide::Result<()> {
let mut config = load_config(CONFIG_PATH).unwrap();
let mut watcher: RecommendedWatcher =
Watcher::new_immediate(|result: Result<Event, Error>| {
let event = result.unwrap();
if event.kind == EventKind::Modify(ModifyKind::Any) {
config = load_config(CONFIG_PATH).unwrap();
}
})?;
watcher.watch(CONFIG_PATH, RecursiveMode::Recursive)?;
let mut app = tide::with_state(config);
app.listen("127.0.0.1:8080").await?;
Ok(())
}
I asked in the Rust Discord beginners chat and 17cupsofcoffee said I should be using a mutex but I have no idea how to do that.