mod constructors;
mod helpers;
mod methods;
mod traits;
use notify::{Event, RecommendedWatcher};
use std::path::PathBuf;
use std::sync::mpsc::Receiver;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum WatchMode {
#[default]
File,
Recursive,
}
#[derive(Debug, Clone)]
pub struct WatchConfig {
pub mode: WatchMode,
pub debounce_ms: u64,
}
impl Default for WatchConfig {
fn default() -> Self {
Self {
mode: WatchMode::File,
debounce_ms: 100,
}
}
}
impl WatchConfig {
pub fn new() -> Self {
Self::default()
}
pub fn mode(mut self, mode: WatchMode) -> Self {
self.mode = mode;
self
}
pub fn debounce_ms(mut self, ms: u64) -> Self {
self.debounce_ms = ms;
self
}
}
pub struct FileWatcher {
pub(crate) watcher: RecommendedWatcher,
pub(crate) rx: Receiver<Result<Event, notify::Error>>,
pub(crate) config: WatchConfig,
pub(crate) changed_paths: Vec<PathBuf>,
}