Skip to main content

FileSystem

Trait FileSystem 

Source
pub trait FileSystem:
    Clone
    + Send
    + Sync
    + 'static {
    // Required methods
    fn read(
        &self,
        path: &Path,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'static>>;
    fn write(
        &self,
        path: &Path,
        contents: Vec<u8>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>;
    fn remove_file(
        &self,
        path: &Path,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>;
    fn create_dir_all(
        &self,
        path: &Path,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>;
    fn exists(
        &self,
        path: &Path,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'static>>;
}
Expand description

Abstraction over the filesystem to support deterministic simulation.

In production, this uses real OS files (std::fs or tokio::fs). In simulation, SimVfs provides an in-memory virtual disk.

Required Methods§

Source

fn read( &self, path: &Path, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'static>>

Read the entire contents of a file into a vector of bytes.

Source

fn write( &self, path: &Path, contents: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>

Write a slice as the entire contents of a file.

Source

fn remove_file( &self, path: &Path, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>

Remove a file from the filesystem.

Source

fn create_dir_all( &self, path: &Path, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>

Create a directory and all of its parent components if they are missing.

Source

fn exists( &self, path: &Path, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'static>>

Return true if the path points to an existing entity.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§