166 releases

new 0.0.211 Apr 15, 2024
0.0.207 Mar 25, 2024
0.0.190 Dec 18, 2023
0.0.187 Nov 27, 2023
0.0.26 Nov 30, 2020

#157 in Filesystem

Download history 1190/week @ 2023-12-23 1552/week @ 2023-12-30 2451/week @ 2024-01-06 2646/week @ 2024-01-13 2096/week @ 2024-01-20 1950/week @ 2024-01-27 2351/week @ 2024-02-03 1620/week @ 2024-02-10 2955/week @ 2024-02-17 4449/week @ 2024-02-24 2529/week @ 2024-03-02 2453/week @ 2024-03-09 2266/week @ 2024-03-16 2530/week @ 2024-03-23 2244/week @ 2024-03-30 2512/week @ 2024-04-06

9,828 downloads per month
Used in 33 crates (8 directly)

MIT/Apache

47KB
804 lines

Virtual File System

VFS records all file changes pushed to it via set_file_contents. As such it only ever stores changes, not the actual content of a file at any given moment. All file changes are logged, and can be retrieved via take_changes method. The pack of changes is then pushed to salsa and triggers incremental recomputation.

Files in VFS are identified with FileIds -- interned paths. The notion of the path, VfsPath is somewhat abstract: at the moment, it is represented as an std::path::PathBuf internally, but this is an implementation detail.

VFS doesn't do IO or file watching itself. For that, see the loader module. loader::Handle is an object-safe trait which abstracts both file loading and file watching. Handle is dynamically configured with a set of directory entries which should be scanned and watched. Handle then asynchronously pushes file changes. Directory entries are configured in free-form via list of globs, it's up to the Handle to interpret the globs in any specific way.

VFS stores a flat list of files. file_set::FileSet can partition this list of files into disjoint sets of files. Traversal-like operations (including getting the neighbor file by the relative path) are handled by the FileSet. FileSets are also pushed to salsa and cause it to re-check mod foo; declarations when files are created or deleted.

FileSet and loader::Entry play similar, but different roles. Both specify the "set of paths/files", one is geared towards file watching, the other towards salsa changes. In particular, single FileSet may correspond to several loader::Entry. For example, a crate from crates.io which uses code generation would have two Entries -- for sources in ~/.cargo, and for generated code in ./target/debug/build. It will have a single FileSet which unions the two sources.

Dependencies

~4–13MB
~96K SLoC