pub struct SourceSet { /* private fields */ }Expand description
An in-memory set of source files keyed by SourcePath.
Language adapters 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.
Trait Implementations§
impl Eq for SourceSet
impl StructuralPartialEq for SourceSet
Auto Trait Implementations§
impl Freeze for SourceSet
impl RefUnwindSafe for SourceSet
impl Send for SourceSet
impl Sync for SourceSet
impl Unpin for SourceSet
impl UnsafeUnpin for SourceSet
impl UnwindSafe for SourceSet
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
Mutably borrows from an owned value. Read more
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
Compare self to
key and return true if they are equal.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> ⓘ
Converts
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> ⓘ
Converts
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