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§
Sourcefn read(
&self,
path: &Path,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'static>>
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.
Sourcefn write(
&self,
path: &Path,
contents: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>
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.
Sourcefn remove_file(
&self,
path: &Path,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>
fn remove_file( &self, path: &Path, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>
Remove a file from the filesystem.
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.