Skip to main content

MemFs

Struct MemFs 

Source
pub struct MemFs { /* private fields */ }
Expand description

In-memory filesystem for tests.

Backed by a BTreeMap (files) and BTreeSet (directories) for deterministic, sorted output. Interior mutability via RefCell lets callers hold &MemFs (shared reference) while still mutating state.

Fidelity contract: write returns an error when the parent directory has not been registered via create_dir_all, faithfully modelling real OS behaviour so tests cannot accidentally skip the parent-creation step.

This type is available in non-test builds so integration tests in later units can import it without feature flags.

Implementations§

Source§

impl MemFs

Source

pub fn new() -> Self

Trait Implementations§

Source§

impl Default for MemFs

Source§

fn default() -> Self

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

impl Fs for MemFs

Source§

fn create_dir_all(&self, path: &Path) -> Result<(), SessionError>

Create path and all missing ancestors, like mkdir -p.
Source§

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

Return true if path exists (file or directory).
Source§

fn read(&self, path: &Path) -> Result<Vec<u8>, SessionError>

Read the entire contents of the file at path.
Source§

fn write(&self, path: &Path, data: &[u8]) -> Result<(), SessionError>

Write data to path, replacing any existing content. Read more
Source§

fn append(&self, path: &Path, data: &[u8]) -> Result<(), SessionError>

Append data to the file at path, creating it if absent. Like write, it errors if the parent directory does not exist.
Source§

fn read_dir(&self, path: &Path) -> Result<Vec<PathBuf>, SessionError>

List immediate children (files and directories) of path, sorted for deterministic iteration.
Source§

fn rename(&self, from: &Path, to: &Path) -> Result<(), SessionError>

Rename / move from to to.
Source§

fn remove(&self, path: &Path) -> Result<(), SessionError>

Remove a file or directory tree at path. Read more

Auto Trait Implementations§

§

impl !Freeze for MemFs

§

impl !RefUnwindSafe for MemFs

§

impl !Sync for MemFs

§

impl Send for MemFs

§

impl Unpin for MemFs

§

impl UnsafeUnpin for MemFs

§

impl UnwindSafe for MemFs

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.