pub struct FileStore { /* private fields */ }Expand description
Process-local file content store.
Default constructs an empty store. Wrap in Arc<RwLock<>> for the
shared ToolContext.file_store field; the lock is taken briefly per
call (insert is one allocation + hash, peek is a HashMap lookup +
substring slice).
Implementations§
Source§impl FileStore
impl FileStore
pub fn new() -> Self
Sourcepub fn insert(
&mut self,
path: PathBuf,
content: String,
mtime: SystemTime,
) -> String
pub fn insert( &mut self, path: PathBuf, content: String, mtime: SystemTime, ) -> String
Push a file snapshot into the store. Returns the assigned
store_id. Any prior entry for the same path is replaced —
re-reading a file overwrites its slot rather than accumulating
stale copies.
store_id shape: fs_<8-hex-of-content-hash>. Hash carries
content+path so unrelated files can’t collide; the prefix
disambiguates from other id namespaces in logs.
Sourcepub fn get(&self, store_id: &str) -> Option<&FileEntry>
pub fn get(&self, store_id: &str) -> Option<&FileEntry>
Look up an entry by store_id. Returns None if invalidated or
never inserted.
Sourcepub fn store_id_for_path(&self, path: &Path) -> Option<&str>
pub fn store_id_for_path(&self, path: &Path) -> Option<&str>
Look up the live store_id for a path (if any). Used by
invalidate-on-edit and by read_file to detect “we already
have this; reuse”.
Sourcepub fn is_stale(&self, store_id: &str, current_mtime: SystemTime) -> bool
pub fn is_stale(&self, store_id: &str, current_mtime: SystemTime) -> bool
Compare the entry’s recorded mtime to a freshly-stat’d one. Returns true when the disk has moved on and the entry should not serve. Caller (typically peek_file) returns a recovery hint pointing at re-read.
Sourcepub fn invalidate(&mut self, path: &Path)
pub fn invalidate(&mut self, path: &Path)
Drop the entry (if any) for a path. Called by edit_file / write_file on success. No-op when the path was never in the store. Idempotent — calling twice with the same path is fine.
Sourcepub fn peek_lines(
&self,
store_id: &str,
start: usize,
end: usize,
) -> Option<String>
pub fn peek_lines( &self, store_id: &str, start: usize, end: usize, ) -> Option<String>
Extract a 1-indexed inclusive line range. [1, 1] returns the
first line; out-of-range tails are clamped. Returns None
only if the store_id is unknown — empty regions return Some("")
so callers can distinguish “no such entry” from “valid request,
nothing in that range”.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of live entries — used by tests and the /context
rich snapshot.
pub fn is_empty(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FileStore
impl RefUnwindSafe for FileStore
impl Send for FileStore
impl Sync for FileStore
impl Unpin for FileStore
impl UnsafeUnpin for FileStore
impl UnwindSafe for FileStore
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> 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