pub struct SourceSet { /* private fields */ }Expand description
An in-memory set of source files keyed by SourcePath.
Frontends read from a SourceSet, never from the file system directly.
That keeps them pure (same set in, same model out), makes them trivially
testable, and lets embedders feed sources from anywhere: a git object
store, an editor buffer, a network service.
Text is stored with line endings normalised to \n.
use sealmap_model::SourceSet;
let mut set = SourceSet::new();
set.insert("src/lib.rs", "pub mod a;\r\n").unwrap();
set.insert("src/a.rs", "pub fn f() {}").unwrap();
// Iteration is always in path order, regardless of insertion order.
let paths: Vec<_> = set.iter().map(|(p, _)| p.as_str()).collect();
assert_eq!(paths, ["src/a.rs", "src/lib.rs"]);
assert_eq!(set.get_str("src/lib.rs"), Some("pub mod a;\n"));Implementations§
Source§impl SourceSet
impl SourceSet
Sourcepub fn insert(
&mut self,
path: impl AsRef<str>,
text: impl AsRef<str>,
) -> Result<(), PathError>
pub fn insert( &mut self, path: impl AsRef<str>, text: impl AsRef<str>, ) -> Result<(), PathError>
Insert or replace a file. The path is normalised; text newlines are
normalised to \n.
Sourcepub fn get(&self, path: &SourcePath) -> Option<&str>
pub fn get(&self, path: &SourcePath) -> Option<&str>
Text of the file at path.
Sourcepub fn get_str(&self, path: &str) -> Option<&str>
pub fn get_str(&self, path: &str) -> Option<&str>
Text of the file at a raw path string (normalised first).
Sourcepub fn iter(&self) -> impl Iterator<Item = (&SourcePath, &str)>
pub fn iter(&self) -> impl Iterator<Item = (&SourcePath, &str)>
Files in path order.
Sourcepub fn paths(&self) -> impl Iterator<Item = &SourcePath>
pub fn paths(&self) -> impl Iterator<Item = &SourcePath>
Paths in order.
Sourcepub fn retain(&mut self, keep: impl FnMut(&SourcePath) -> bool)
pub fn retain(&mut self, keep: impl FnMut(&SourcePath) -> bool)
Keep only files for which keep returns true.
Sourcepub fn load_dir(root: &Path, options: &LoadOptions) -> Result<Self>
pub fn load_dir(root: &Path, options: &LoadOptions) -> Result<Self>
Recursively load every matching file under root.
Symlinks are not followed and files that are not valid UTF-8 are
skipped, so the result depends only on the bytes under root.