diff options
author | Akshay <[email protected]> | 2021-11-06 09:20:58 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-11-06 09:20:58 +0000 |
commit | 63eba9d5c697e466d952588568719d0de1244ae4 (patch) | |
tree | 5fe5b75cb59ea3a1e9e01deaa468fc255eb7dc95 | |
parent | 96a404acfcd628bc23279df1d95698c111b22a02 (diff) |
introduce ReadOnlyVfs::singleton
create a VFS with exactly one file, handy for operations involving a
single buffer or file
-rw-r--r-- | vfs/src/lib.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/vfs/src/lib.rs b/vfs/src/lib.rs index 98bd1c3..8b5df79 100644 --- a/vfs/src/lib.rs +++ b/vfs/src/lib.rs | |||
@@ -36,6 +36,11 @@ pub struct ReadOnlyVfs { | |||
36 | } | 36 | } |
37 | 37 | ||
38 | impl ReadOnlyVfs { | 38 | impl ReadOnlyVfs { |
39 | pub fn singleton<P: AsRef<Path>>(path: P, contents: &[u8]) -> Self { | ||
40 | let mut vfs = ReadOnlyVfs::default(); | ||
41 | vfs.set_file_contents(path, contents); | ||
42 | vfs | ||
43 | } | ||
39 | pub fn alloc_file_id<P: AsRef<Path>>(&mut self, path: P) -> FileId { | 44 | pub fn alloc_file_id<P: AsRef<Path>>(&mut self, path: P) -> FileId { |
40 | self.interner.intern(path.as_ref().to_owned()) | 45 | self.interner.intern(path.as_ref().to_owned()) |
41 | } | 46 | } |