From 63eba9d5c697e466d952588568719d0de1244ae4 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 6 Nov 2021 14:50:58 +0530 Subject: introduce ReadOnlyVfs::singleton create a VFS with exactly one file, handy for operations involving a single buffer or file --- vfs/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) 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 { } impl ReadOnlyVfs { + pub fn singleton>(path: P, contents: &[u8]) -> Self { + let mut vfs = ReadOnlyVfs::default(); + vfs.set_file_contents(path, contents); + vfs + } pub fn alloc_file_id>(&mut self, path: P) -> FileId { self.interner.intern(path.as_ref().to_owned()) } -- cgit v1.2.3