pub struct FakeFileSystem { /* private fields */ }Expand description
An in-memory filesystem.
Paths are normalised (. and .. resolved lexically) so callers can hand it either
absolute or relative paths and get consistent answers. Interior mutability via
Mutex keeps it usable behind the &self trait methods and Send + Sync for the
worker thread.
Implementations§
Source§impl FakeFileSystem
impl FakeFileSystem
pub fn new() -> Self
Sourcepub fn with_paths(paths: &[&str]) -> Self
pub fn with_paths(paths: &[&str]) -> Self
Build a tree from a path list. Trailing / means directory; parents are implied.
ⓘ
FakeFileSystem::with_paths(&["/proj/src/main.rs", "/proj/Cargo.toml", "/proj/target/"]);Sourcepub fn add_dir(&self, path: impl AsRef<Path>) -> &Self
pub fn add_dir(&self, path: impl AsRef<Path>) -> &Self
Insert a directory and every missing ancestor.
Sourcepub fn add_file(&self, path: impl AsRef<Path>, contents: &[u8]) -> &Self
pub fn add_file(&self, path: impl AsRef<Path>, contents: &[u8]) -> &Self
Insert a file with contents, creating missing ancestor directories.
Sourcepub fn add_symlink(
&self,
path: impl AsRef<Path>,
target: impl AsRef<Path>,
) -> &Self
pub fn add_symlink( &self, path: impl AsRef<Path>, target: impl AsRef<Path>, ) -> &Self
Insert a symlink. It is listed but never traversed, matching the real service.
Trait Implementations§
Source§impl Debug for FakeFileSystem
impl Debug for FakeFileSystem
Source§impl Default for FakeFileSystem
impl Default for FakeFileSystem
Source§fn default() -> FakeFileSystem
fn default() -> FakeFileSystem
Returns the “default value” for a type. Read more
Source§impl FileSystemService for FakeFileSystem
impl FileSystemService for FakeFileSystem
Source§fn read_dir(&self, path: &Path) -> FsResult<Vec<DirEntryInfo>>
fn read_dir(&self, path: &Path) -> FsResult<Vec<DirEntryInfo>>
List one directory level. Does not recurse — the tree is lazy (ADR-0005 §2). Read more
fn read_file(&self, path: &Path) -> FsResult<Vec<u8>>
Source§fn create_file(&self, path: &Path) -> FsResult<()>
fn create_file(&self, path: &Path) -> FsResult<()>
Create an empty file. Errors with
FsError::AlreadyExists rather than truncating.Source§fn write_file(&self, path: &Path, contents: &[u8]) -> FsResult<()>
fn write_file(&self, path: &Path, contents: &[u8]) -> FsResult<()>
Replace a file’s contents, creating it if absent. Read more
Source§fn create_dir(&self, path: &Path) -> FsResult<()>
fn create_dir(&self, path: &Path) -> FsResult<()>
Create a directory, including missing parents.
fn rename(&self, from: &Path, to: &Path) -> FsResult<()>
fn remove_file(&self, path: &Path) -> FsResult<()>
Auto Trait Implementations§
impl !Freeze for FakeFileSystem
impl RefUnwindSafe for FakeFileSystem
impl Send for FakeFileSystem
impl Sync for FakeFileSystem
impl Unpin for FakeFileSystem
impl UnsafeUnpin for FakeFileSystem
impl UnwindSafe for FakeFileSystem
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.