pub struct FileIdMap { /* private fields */ }Expand description
Bidirectional mapping between FileId and the current path of each
tracked file (§5.8).
Invariants maintained by all mutating methods:
- Every
FileIdmaps to exactly one path. - Every path maps to exactly one
FileId. - The two maps are always consistent with each other.
These invariants guarantee O(1) lookup in both directions.
Implementations§
Source§impl FileIdMap
impl FileIdMap
Sourcepub fn track_new(&mut self, path: PathBuf) -> Result<FileId, FileIdMapError>
pub fn track_new(&mut self, path: PathBuf) -> Result<FileId, FileIdMapError>
Track a newly created file.
Assigns a fresh random FileId to path and returns it.
§Errors
Returns FileIdMapError::PathAlreadyTracked if path is already
tracked. A file must be deleted before it can be re-created at the
same path.
Sourcepub fn track_rename(
&mut self,
old_path: &Path,
new_path: PathBuf,
) -> Result<FileId, FileIdMapError>
pub fn track_rename( &mut self, old_path: &Path, new_path: PathBuf, ) -> Result<FileId, FileIdMapError>
Track a file rename: old_path → new_path.
The FileId is preserved — only the path mapping changes.
§Errors
FileIdMapError::PathNotTrackedifold_pathis not tracked.FileIdMapError::PathAlreadyTrackedifnew_pathis already tracked by a different file.
Sourcepub fn track_copy(
&mut self,
src_path: &Path,
dst_path: PathBuf,
) -> Result<FileId, FileIdMapError>
pub fn track_copy( &mut self, src_path: &Path, dst_path: PathBuf, ) -> Result<FileId, FileIdMapError>
Track a file copy: create dst_path as a copy of src_path.
Assigns a new random FileId to the copy. The source file
keeps its original identity. This is explicit, not inferred from
content similarity.
§Errors
FileIdMapError::PathNotTrackedifsrc_pathis not tracked.FileIdMapError::PathAlreadyTrackedifdst_pathis already tracked.
Sourcepub fn track_delete(&mut self, path: &Path) -> Result<FileId, FileIdMapError>
pub fn track_delete(&mut self, path: &Path) -> Result<FileId, FileIdMapError>
Track a file deletion.
Removes both mappings. Returns the FileId that was assigned to
the deleted file.
§Errors
Returns FileIdMapError::PathNotTracked if path is not tracked.
Sourcepub fn id_for_path(&self, path: &Path) -> Option<FileId>
pub fn id_for_path(&self, path: &Path) -> Option<FileId>
Look up the FileId for a given path. Returns None if untracked.
Sourcepub fn path_for_id(&self, id: FileId) -> Option<&Path>
pub fn path_for_id(&self, id: FileId) -> Option<&Path>
Look up the current path for a given FileId. Returns None if
not tracked (file was deleted or never registered).
Sourcepub fn contains_path(&self, path: &Path) -> bool
pub fn contains_path(&self, path: &Path) -> bool
Return true if path is currently tracked.
Sourcepub fn contains_id(&self, id: FileId) -> bool
pub fn contains_id(&self, id: FileId) -> bool
Return true if id is currently tracked.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&Path, FileId)>
pub fn iter(&self) -> impl Iterator<Item = (&Path, FileId)>
Iterate over all (path, FileId) entries in sorted path order.
Sourcepub fn load(path: &Path) -> Result<Self, FileIdMapError>
pub fn load(path: &Path) -> Result<Self, FileIdMapError>
Load the map from a .manifold/fileids JSON file.
Returns an empty map if the file does not exist (first run).
§Errors
Returns FileIdMapError::Io on I/O failure (other than not-found),
or FileIdMapError::Json on JSON parse failure.
Sourcepub fn save(&self, path: &Path) -> Result<(), FileIdMapError>
pub fn save(&self, path: &Path) -> Result<(), FileIdMapError>
Save the map to a .manifold/fileids JSON file.
Writes are atomic: content is first written to <path>.tmp then
renamed over the destination. This prevents a crash mid-write from
leaving a corrupt file.
Parent directories are created if they don’t exist.
§Errors
Returns FileIdMapError::Io on I/O failure, or
FileIdMapError::Json on serialization failure.
Trait Implementations§
impl Eq for FileIdMap
impl StructuralPartialEq for FileIdMap
Auto Trait Implementations§
impl Freeze for FileIdMap
impl RefUnwindSafe for FileIdMap
impl Send for FileIdMap
impl Sync for FileIdMap
impl Unpin for FileIdMap
impl UnsafeUnpin for FileIdMap
impl UnwindSafe for FileIdMap
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.