pub struct FakeFilesystem { /* private fields */ }Expand description
In-memory filesystem for tests.
Files are stored as byte vectors keyed by their (absolute or relative)
path. Directory entries are derived automatically from file paths. All
methods that mutate state accept &self via interior mutability
(RefCell) so that test helpers and trait implementations share the same
borrow.
Implementations§
Source§impl FakeFilesystem
impl FakeFilesystem
pub fn new() -> Self
Sourcepub fn set_fail_on_write(&self, path: impl Into<PathBuf>)
pub fn set_fail_on_write(&self, path: impl Into<PathBuf>)
Cause the next write() to the given path to return an error.
Sourcepub fn set_fail_on_rename(&self, path: impl Into<PathBuf>)
pub fn set_fail_on_rename(&self, path: impl Into<PathBuf>)
Cause rename() targeting the given destination path to return an error.
Sourcepub fn set_fail_on_copy(&self, fail: bool)
pub fn set_fail_on_copy(&self, fail: bool)
Cause all copy_file() calls to return an error.
Sourcepub fn add_file(&self, path: impl Into<PathBuf>, content: impl Into<Vec<u8>>)
pub fn add_file(&self, path: impl Into<PathBuf>, content: impl Into<Vec<u8>>)
Insert a file with the given content, automatically registering all ancestor directories.
Sourcepub fn get_file_content(&self, path: &Path) -> Option<Vec<u8>>
pub fn get_file_content(&self, path: &Path) -> Option<Vec<u8>>
Return the stored content for a path, or None if absent.
Sourcepub fn file_exists(&self, path: &Path) -> bool
pub fn file_exists(&self, path: &Path) -> bool
Return true if the path has been added as a file.
Trait Implementations§
Source§impl Default for FakeFilesystem
impl Default for FakeFilesystem
Source§impl Filesystem for FakeFilesystem
impl Filesystem for FakeFilesystem
fn exists(&self, path: &Path) -> bool
fn is_dir(&self, path: &Path) -> bool
fn is_file(&self, path: &Path) -> bool
fn read_to_string(&self, path: &Path) -> Result<String>
fn read(&self, path: &Path) -> Result<Vec<u8>>
fn write(&self, path: &Path, contents: &str) -> Result<()>
fn write_bytes(&self, path: &Path, contents: &[u8]) -> Result<()>
fn create_dir_all(&self, path: &Path) -> Result<()>
fn copy_file(&self, src: &Path, dest: &Path) -> Result<()>
Source§fn rename(&self, from: &Path, to: &Path) -> Result<()>
fn rename(&self, from: &Path, to: &Path) -> Result<()>
Atomically rename
from to to, replacing to if it already exists.fn remove_file(&self, path: &Path) -> Result<()>
fn remove_dir_all(&self, path: &Path) -> Result<()>
fn read_dir(&self, path: &Path) -> Result<Vec<DirEntry>>
fn canonicalize(&self, path: &Path) -> Result<PathBuf>
Auto Trait Implementations§
impl !Freeze for FakeFilesystem
impl !RefUnwindSafe for FakeFilesystem
impl !Sync for FakeFilesystem
impl Send 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