Skip to main content

SimFs

Struct SimFs 

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

Deterministic in-memory filesystem with fault injection.

Each operation checks the configured fault rules. If a rule matches, the simulation RNG decides (based on probability) whether to inject the fault.

use vortex_fs::{SimFs, VortexFs};

let mut fs = SimFs::new(42);
fs.create_dir_all("/data/logs").unwrap();
fs.write_file("/data/logs/app.log", b"hello").unwrap();
assert!(fs.exists("/data/logs/app.log"));
assert_eq!(fs.read_file("/data/logs/app.log").unwrap(), b"hello");

Implementations§

Source§

impl SimFs

Source

pub fn new(seed: u64) -> Self

Create a new in-memory filesystem with the given seed.

Source

pub fn with_faults(seed: u64, config: FsFaultConfig) -> Self

Create with fault injection configuration.

Source

pub fn set_fault_config(&mut self, config: FsFaultConfig)

Set the fault configuration.

Source

pub fn total_bytes_written(&self) -> u64

Get total bytes written so far.

Source

pub fn entry_count(&self) -> usize

Number of entries (files + directories).

Trait Implementations§

Source§

impl VortexFs for SimFs

Source§

fn read_file(&self, path: &str) -> VortexFsResult<Vec<u8>>

Read the entire contents of a file.
Source§

fn write_file(&mut self, path: &str, data: &[u8]) -> VortexFsResult<()>

Write data to a file (creates or overwrites).
Source§

fn append_file(&mut self, path: &str, data: &[u8]) -> VortexFsResult<()>

Append data to a file (creates if not exists).
Source§

fn remove_file(&mut self, path: &str) -> VortexFsResult<()>

Remove a file.
Source§

fn rename(&mut self, from: &str, to: &str) -> VortexFsResult<()>

Rename a file or directory.
Source§

fn create_dir_all(&mut self, path: &str) -> VortexFsResult<()>

Create a directory (and all parent directories).
Source§

fn remove_dir(&mut self, path: &str) -> VortexFsResult<()>

Remove an empty directory.
Source§

fn read_dir(&self, path: &str) -> VortexFsResult<Vec<String>>

List the entries in a directory.
Source§

fn metadata(&self, path: &str) -> VortexFsResult<FileMetadata>

Get metadata about a file or directory.
Source§

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

Check if a path exists.
Source§

fn fsync(&mut self, path: &str) -> VortexFsResult<()>

Flush / fsync a file (no-op for in-memory, real sync for production).

Auto Trait Implementations§

§

impl Freeze for SimFs

§

impl RefUnwindSafe for SimFs

§

impl Send for SimFs

§

impl Sync for SimFs

§

impl Unpin for SimFs

§

impl UnsafeUnpin for SimFs

§

impl UnwindSafe for SimFs

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