pub struct FileItem {
pub path: PathBuf,
pub relative_path: String,
pub relative_path_lower: String,
pub file_name: String,
pub file_name_lower: String,
pub size: u64,
pub modified: u64,
pub access_frecency_score: i64,
pub modification_frecency_score: i64,
pub total_frecency_score: i64,
pub git_status: Option<Status>,
pub is_binary: bool,
/* private fields */
}Expand description
A single indexed file with metadata, frecency scores, and lazy content cache.
File contents are initialized lazily on the first grep access and cached for subsequent searches. On Unix, uses mmap backed by the kernel page cache. On Windows, reads into a heap buffer to avoid holding file handles open.
Thread-safety: OnceLock provides lock-free reads after initialization.
Each file is only searched by one rayon worker at a time via par_iter.
Fields§
§path: PathBuf§relative_path: String§relative_path_lower: String§file_name: String§file_name_lower: String§size: u64§modified: u64§access_frecency_score: i64§modification_frecency_score: i64§total_frecency_score: i64§git_status: Option<Status>§is_binary: boolImplementations§
Source§impl FileItem
impl FileItem
Sourcepub fn new_raw(
path: PathBuf,
relative_path: String,
file_name: String,
size: u64,
modified: u64,
git_status: Option<Status>,
is_binary: bool,
) -> Self
pub fn new_raw( path: PathBuf, relative_path: String, file_name: String, size: u64, modified: u64, git_status: Option<Status>, is_binary: bool, ) -> Self
Create a new FileItem with all fields specified and an empty (not yet loaded) mmap.
Sourcepub fn invalidate_mmap(&mut self)
pub fn invalidate_mmap(&mut self)
Invalidate the cached content so the next get_content() call creates a fresh one.
Call this when the background watcher detects that the file has been modified. On Unix, a file that is truncated while mapped can cause SIGBUS. On Windows, the stale buffer simply won’t reflect the new contents. In both cases, invalidating ensures a fresh read on the next access.
Sourcepub fn get_content(&self) -> Option<&[u8]>
pub fn get_content(&self) -> Option<&[u8]>
Get the cached file contents or lazily load them. Returns None if the
file is too large, empty, or can’t be opened.
After the first call, this is lock-free (just an atomic load + pointer deref). On Unix, uses mmap backed by the kernel page cache. On Windows, reads into a heap buffer so the file handle is released immediately.
Trait Implementations§
Source§impl Constrainable for FileItem
impl Constrainable for FileItem
Source§fn relative_path(&self) -> &str
fn relative_path(&self) -> &str
Source§fn relative_path_lower(&self) -> &str
fn relative_path_lower(&self) -> &str
Source§fn git_status(&self) -> Option<Status>
fn git_status(&self) -> Option<Status>
Auto Trait Implementations§
impl !Freeze for FileItem
impl RefUnwindSafe for FileItem
impl Send for FileItem
impl Sync for FileItem
impl Unpin for FileItem
impl UnsafeUnpin for FileItem
impl UnwindSafe for FileItem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more