pub struct MemoryFileSystem { /* private fields */ }Expand description
File system that stores all content in memory.
The file system supports files and directories. Paths are case-sensitive.
The implementation doesn’t aim at fully capturing the behavior of a real file system. The implementation intentionally doesn’t support:
- symlinks
- hardlinks
- permissions: All files and directories have the permission 0755.
Use a tempdir with the real file system to test these advanced file system features and behavior.
Implementations§
Source§impl MemoryFileSystem
impl MemoryFileSystem
pub fn new() -> Self
Sourcepub fn with_current_directory(cwd: impl AsRef<SystemPath>) -> Self
pub fn with_current_directory(cwd: impl AsRef<SystemPath>) -> Self
Creates a new, empty in memory file system with the given current working directory.
pub fn current_directory(&self) -> &SystemPath
pub fn metadata(&self, path: impl AsRef<SystemPath>) -> Result<Metadata>
pub fn canonicalize( &self, path: impl AsRef<SystemPath>, ) -> Result<SystemPathBuf>
pub fn is_file(&self, path: impl AsRef<SystemPath>) -> bool
pub fn is_directory(&self, path: impl AsRef<SystemPath>) -> bool
pub fn is_executable(&self, path: &SystemPath) -> bool
pub fn read_to_string(&self, path: impl AsRef<SystemPath>) -> Result<String>
pub fn exists(&self, path: &SystemPath) -> bool
pub fn virtual_path_exists(&self, path: &SystemVirtualPath) -> bool
Sourcepub fn write_file(
&self,
path: impl AsRef<SystemPath>,
content: impl AsRef<[u8]>,
) -> Result<()>
pub fn write_file( &self, path: impl AsRef<SystemPath>, content: impl AsRef<[u8]>, ) -> Result<()>
Stores a new file in the file system.
The operation overrides the content for an existing file with the same normalized path.
Sourcepub fn write_files_all<P, C>(
&self,
files: impl IntoIterator<Item = (P, C)>,
) -> Result<()>
pub fn write_files_all<P, C>( &self, files: impl IntoIterator<Item = (P, C)>, ) -> Result<()>
Writes the files to the file system.
The operation overrides existing files with the same normalized path.
Enclosing directories are automatically created if they don’t exist.
Sourcepub fn write_file_all(
&self,
path: impl AsRef<SystemPath>,
content: impl AsRef<[u8]>,
) -> Result<()>
pub fn write_file_all( &self, path: impl AsRef<SystemPath>, content: impl AsRef<[u8]>, ) -> Result<()>
Stores a new file in the file system.
The operation overrides the content for an existing file with the same normalized path.
Enclosing directories are automatically created if they don’t exist.
Sourcepub fn write_virtual_file(
&self,
path: impl AsRef<SystemVirtualPath>,
content: impl AsRef<[u8]>,
)
pub fn write_virtual_file( &self, path: impl AsRef<SystemVirtualPath>, content: impl AsRef<[u8]>, )
Stores a new virtual file in the file system.
The operation overrides the content for an existing virtual file with the same path.
Sourcepub fn walk_directory(
&self,
path: impl AsRef<SystemPath>,
) -> WalkDirectoryBuilder
pub fn walk_directory( &self, path: impl AsRef<SystemPath>, ) -> WalkDirectoryBuilder
Returns a builder for walking the directory tree of path.
The only files that are ignored when setting WalkDirectoryBuilder::standard_filters
are hidden files (files with a name starting with a .).
pub fn remove_file(&self, path: impl AsRef<SystemPath>) -> Result<()>
pub fn remove_virtual_file( &self, path: impl AsRef<SystemVirtualPath>, ) -> Result<()>
Sourcepub fn touch(&self, path: impl AsRef<SystemPath>) -> Result<()>
pub fn touch(&self, path: impl AsRef<SystemPath>) -> Result<()>
Sets the last modified timestamp of the file stored at path to now.
Creates a new file if the file at path doesn’t exist.
Sourcepub fn create_directory_all(&self, path: impl AsRef<SystemPath>) -> Result<()>
pub fn create_directory_all(&self, path: impl AsRef<SystemPath>) -> Result<()>
Creates a directory at path. All enclosing directories are created if they don’t exist.
Sourcepub fn remove_directory(&self, path: impl AsRef<SystemPath>) -> Result<()>
pub fn remove_directory(&self, path: impl AsRef<SystemPath>) -> Result<()>
Deletes the directory at path.
§Errors
- If the directory is not empty
- The
pathis not a directory - The
pathdoes not exist
pub fn read_directory( &self, path: impl AsRef<SystemPath>, ) -> Result<ReadDirectory>
Sourcepub fn remove_all(&self)
pub fn remove_all(&self)
Removes all files and directories except the current working directory.
Trait Implementations§
Source§impl Clone for MemoryFileSystem
impl Clone for MemoryFileSystem
Source§fn clone(&self) -> MemoryFileSystem
fn clone(&self) -> MemoryFileSystem
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MemoryFileSystem
impl Debug for MemoryFileSystem
Auto Trait Implementations§
impl Freeze for MemoryFileSystem
impl RefUnwindSafe for MemoryFileSystem
impl Send for MemoryFileSystem
impl Sync for MemoryFileSystem
impl Unpin for MemoryFileSystem
impl UnsafeUnpin for MemoryFileSystem
impl UnwindSafe for MemoryFileSystem
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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> ⓘ
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> ⓘ
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