Skip to main content

MemoryFileSystem

Struct MemoryFileSystem 

Source
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

Source

pub fn new() -> Self

Source

pub fn with_current_directory(cwd: impl AsRef<SystemPath>) -> Self

Creates a new, empty in memory file system with the given current working directory.

Source

pub fn current_directory(&self) -> &SystemPath

Source

pub fn metadata(&self, path: impl AsRef<SystemPath>) -> Result<Metadata>

Source

pub fn canonicalize( &self, path: impl AsRef<SystemPath>, ) -> Result<SystemPathBuf>

Source

pub fn is_file(&self, path: impl AsRef<SystemPath>) -> bool

Source

pub fn is_directory(&self, path: impl AsRef<SystemPath>) -> bool

Source

pub fn is_executable(&self, path: &SystemPath) -> bool

Source

pub fn read_to_string(&self, path: impl AsRef<SystemPath>) -> Result<String>

Source

pub fn exists(&self, path: &SystemPath) -> bool

Source

pub fn virtual_path_exists(&self, path: &SystemVirtualPath) -> bool

Source

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.

Source

pub fn write_files_all<P, C>( &self, files: impl IntoIterator<Item = (P, C)>, ) -> Result<()>
where P: AsRef<SystemPath>, C: ToString,

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.

Source

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.

Source

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.

Source

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 .).

Source

pub fn remove_file(&self, path: impl AsRef<SystemPath>) -> Result<()>

Source

pub fn remove_virtual_file( &self, path: impl AsRef<SystemVirtualPath>, ) -> Result<()>

Source

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.

Source

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.

Source

pub fn remove_directory(&self, path: impl AsRef<SystemPath>) -> Result<()>

Deletes the directory at path.

§Errors
  • If the directory is not empty
  • The path is not a directory
  • The path does not exist
Source

pub fn read_directory( &self, path: impl AsRef<SystemPath>, ) -> Result<ReadDirectory>

Source

pub fn remove_all(&self)

Removes all files and directories except the current working directory.

Trait Implementations§

Source§

impl Clone for MemoryFileSystem

Source§

fn clone(&self) -> MemoryFileSystem

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryFileSystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MemoryFileSystem

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Lookup<T> for T

Source§

fn into_owned(self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more