Skip to content

Commit

Permalink
Allow flexible handle instead of direct borrow for file ids in the Fi…
Browse files Browse the repository at this point in the history
…leIdCache
  • Loading branch information
florian-g2 committed Jan 7, 2025
1 parent d86a44d commit ed6fdec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions notify-debouncer-full/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{
collections::HashMap,
path::{Path, PathBuf},
};

use std::ops::Deref;
use file_id::{get_file_id, FileId};
use notify::RecursiveMode;
use walkdir::WalkDir;
Expand All @@ -14,7 +14,7 @@ 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>;
fn cached_file_id(&self, path: &Path) -> Option<impl Deref<Target=FileId>>;

/// Add a new path to the cache or update its value.
///
Expand Down Expand Up @@ -64,7 +64,7 @@ impl FileIdMap {
}

impl FileIdCache for FileIdMap {
fn cached_file_id(&self, path: &Path) -> Option<&FileId> {
fn cached_file_id(&self, path: &Path) -> Option<impl Deref<Target=FileId>> {
self.paths.get(path)
}

Expand Down Expand Up @@ -104,8 +104,8 @@ impl NoCache {
}

impl FileIdCache for NoCache {
fn cached_file_id(&self, _path: &Path) -> Option<&FileId> {
None
fn cached_file_id(&self, _path: &Path) -> Option<impl Deref<Target=FileId>> {
Option::<&FileId>::None
}

fn add_path(&mut self, _path: &Path, _recursive_mode: RecursiveMode) {}
Expand Down
4 changes: 2 additions & 2 deletions notify-debouncer-full/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl<T: FileIdCache> DebounceDataInner<T> {
let path = &event.paths[0];

// store event
let file_id = self.cache.cached_file_id(path).cloned();
let file_id = self.cache.cached_file_id(path).as_deref().cloned();
self.rename_event = Some((DebouncedEvent::new(event.clone(), time), file_id));

self.cache.remove_path(path);
Expand Down Expand Up @@ -368,7 +368,7 @@ impl<T: FileIdCache> DebounceDataInner<T> {
.and_then(|from_file_id| {
self.cache
.cached_file_id(&event.paths[0])
.map(|to_file_id| from_file_id == to_file_id)
.map(|to_file_id| *from_file_id == *to_file_id)
})
.unwrap_or_default();

Expand Down

0 comments on commit ed6fdec

Please sign in to comment.