filesentry 0.1.0

robust (recursive) file watcher
Documentation
use std::path::Path;
use std::time::Duration;

use ignore::WalkBuilder;

use crate::events::Events;

pub type SetupWalk = Box<dyn FnMut(&Path) -> WalkBuilder + Send>;
pub type Handler = Box<dyn FnMut(Events) -> bool + Send>;

pub struct Config {
    pub(crate) setup_walk: Option<SetupWalk>,
    pub(crate) settle_time: Duration,
    pub(crate) handlers: Vec<Handler>,
}

impl std::fmt::Debug for Config {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Config")
            .field("settle_time", &self.settle_time)
            .finish_non_exhaustive()
    }
}

impl Config {
    pub(crate) fn make_walk_builder(&mut self, path: &Path) -> WalkBuilder {
        let mut walk = self
            .setup_walk
            .as_deref_mut()
            .map(|f| f(path))
            .unwrap_or_else(|| WalkBuilder::new(path));
        // always required for correctness
        walk.follow_links(false).skip_stdout(true);
        walk
    }
}