mirror of
https://github.com/bevyengine/bevy
synced 2024-12-27 13:33:08 +00:00
9f4c8b1b9a
Fix errors and panics to typical Rust conventions
26 lines
903 B
Rust
26 lines
903 B
Rust
use crossbeam_channel::Receiver;
|
|
use notify::{Event, RecommendedWatcher, RecursiveMode, Result, Watcher};
|
|
use std::path::Path;
|
|
|
|
/// Watches for changes to assets on the filesystem. This is used by the `AssetServer` to reload them
|
|
pub struct FilesystemWatcher {
|
|
pub watcher: RecommendedWatcher,
|
|
pub receiver: Receiver<Result<Event>>,
|
|
}
|
|
|
|
impl Default for FilesystemWatcher {
|
|
fn default() -> Self {
|
|
let (sender, receiver) = crossbeam_channel::unbounded();
|
|
let watcher: RecommendedWatcher = Watcher::new_immediate(move |res| {
|
|
sender.send(res).expect("Watch event send failure.");
|
|
})
|
|
.expect("Failed to create filesystem watcher.");
|
|
FilesystemWatcher { watcher, receiver }
|
|
}
|
|
}
|
|
|
|
impl FilesystemWatcher {
|
|
pub fn watch<P: AsRef<Path>>(&mut self, path: P) -> Result<()> {
|
|
self.watcher.watch(path, RecursiveMode::Recursive)
|
|
}
|
|
}
|