cargo fmt

This commit is contained in:
Daniel Faust
2023-05-09 14:36:50 +02:00
committed by Aron Heinecke
parent 4fc2a10814
commit b2b05ee24d
2 changed files with 27 additions and 19 deletions
+20 -12
View File
@@ -24,7 +24,7 @@
//! # fn main() {
//! // setup initial watcher backend config
//! let config = Config::default();
//!
//!
//! // Select recommended watcher for debouncer.
//! // Using a callback here, could also be a channel.
//! let mut debouncer = new_debouncer(Duration::from_secs(2), None, |res: DebounceEventResult| {
@@ -266,7 +266,7 @@ pub fn new_debouncer_opt<F: DebounceEventHandler, T: Watcher>(
timeout: Duration,
tick_rate: Option<Duration>,
mut event_handler: F,
config: notify::Config
config: notify::Config,
) -> Result<Debouncer<T>, Error> {
let data = DebounceData::default();
@@ -320,15 +320,18 @@ pub fn new_debouncer_opt<F: DebounceEventHandler, T: Watcher>(
}
})?;
let watcher = T::new(move |e: Result<Event, Error>| {
let mut lock = data.lock().expect("Can't lock debouncer data!");
let watcher = T::new(
move |e: Result<Event, Error>| {
let mut lock = data.lock().expect("Can't lock debouncer data!");
match e {
Ok(e) => lock.add_event(e),
// can't have multiple TX, so we need to pipe that through our debouncer
Err(e) => lock.add_error(e),
}
}, config)?;
match e {
Ok(e) => lock.add_event(e),
// can't have multiple TX, so we need to pipe that through our debouncer
Err(e) => lock.add_error(e),
}
},
config,
)?;
let guard = Debouncer {
watcher,
@@ -347,7 +350,12 @@ pub fn new_debouncer_opt<F: DebounceEventHandler, T: Watcher>(
pub fn new_debouncer<F: DebounceEventHandler>(
timeout: Duration,
tick_rate: Option<Duration>,
event_handler: F
event_handler: F,
) -> Result<Debouncer<RecommendedWatcher>, Error> {
new_debouncer_opt::<F, RecommendedWatcher>(timeout, tick_rate, event_handler, notify::Config::default())
new_debouncer_opt::<F, RecommendedWatcher>(
timeout,
tick_rate,
event_handler,
notify::Config::default(),
)
}
+7 -7
View File
@@ -8,26 +8,26 @@ use notify::RecursiveMode;
use walkdir::WalkDir;
/// The interface of a file ID cache.
///
///
/// This trait can be implemented for an existing cache, if it already holds `FileId`s.
pub trait FileIdCache {
/// Get a `FileId` from the cache for a given `path`.
///
///
/// If the path is not cached, `None` should be returned and there should not be any attempt to read the file ID from disk.
fn cached_file_id(&self, path: &Path) -> Option<&FileId>;
/// Add a new path to the cache or update its value.
///
///
/// This will be called if a new file or directory is created or if an existing file is overridden.
fn add_path(&mut self, path: &Path);
/// Remove a path from the cache.
///
///
/// This will be called if a file or directory is deleted.
fn remove_path(&mut self, path: &Path);
/// Re-scan all paths.
///
///
/// This will be called if the notification back-end has dropped events.
fn rescan(&mut self);
}
@@ -49,7 +49,7 @@ impl FileIdMap {
}
/// Add a path to the cache.
///
///
/// If `recursive_mode` is `Recursive`, all children will be added to the cache as well
/// and all paths will be kept up-to-date in case of changes like new files being added,
/// files being removed or renamed.
@@ -62,7 +62,7 @@ impl FileIdMap {
}
/// Remove a path form the cache.
///
///
/// If the path was added with `Recursive` mode, all children will also be removed from the cache.
pub fn remove_root(&mut self, path: impl AsRef<Path>) {
self.roots.retain(|(root, _)| !root.starts_with(&path));