Skip to main content

FileSystemExt

Trait FileSystemExt 

Source
pub trait FileSystemExt: FileSystem {
    // Provided methods
    fn read_file_async(
        &self,
        path: &Path,
    ) -> impl Future<Output = Result<Vec<u8>>> + Send { ... }
    fn read_range_async(
        &self,
        path: &Path,
        offset: u64,
        len: usize,
    ) -> impl Future<Output = Result<Vec<u8>>> + Send { ... }
    fn count_line_feeds_in_range_async(
        &self,
        path: &Path,
        offset: u64,
        len: usize,
    ) -> impl Future<Output = Result<usize>> + Send { ... }
    fn write_file_async(
        &self,
        path: &Path,
        data: &[u8],
    ) -> impl Future<Output = Result<()>> + Send { ... }
    fn metadata_async(
        &self,
        path: &Path,
    ) -> impl Future<Output = Result<FileMetadata>> + Send { ... }
    fn exists_async(&self, path: &Path) -> impl Future<Output = bool> + Send { ... }
    fn is_dir_async(
        &self,
        path: &Path,
    ) -> impl Future<Output = Result<bool>> + Send { ... }
    fn is_file_async(
        &self,
        path: &Path,
    ) -> impl Future<Output = Result<bool>> + Send { ... }
    fn read_dir_async(
        &self,
        path: &Path,
    ) -> impl Future<Output = Result<Vec<DirEntry>>> + Send { ... }
    fn canonicalize_async(
        &self,
        path: &Path,
    ) -> impl Future<Output = Result<PathBuf>> + Send { ... }
}
Expand description

Async extension trait for FileSystem

This trait provides async versions of FileSystem methods using native Rust async fn (no async_trait crate needed). Default implementations simply call the sync methods, which works for local filesystem operations.

For truly async backends (network FS, remote agents), implementations can override these methods with actual async implementations.

Note: This trait is NOT object-safe due to async fn. Use generics (impl FileSystem or F: FileSystem) instead of dyn FileSystem when async methods are needed.

§Example

async fn list_files<F: FileSystem>(fs: &F, path: &Path) -> io::Result<Vec<DirEntry>> {
    fs.read_dir_async(path).await
}

Provided Methods§

Source

fn read_file_async( &self, path: &Path, ) -> impl Future<Output = Result<Vec<u8>>> + Send

Async version of read_file

Source

fn read_range_async( &self, path: &Path, offset: u64, len: usize, ) -> impl Future<Output = Result<Vec<u8>>> + Send

Async version of read_range

Source

fn count_line_feeds_in_range_async( &self, path: &Path, offset: u64, len: usize, ) -> impl Future<Output = Result<usize>> + Send

Async version of count_line_feeds_in_range

Source

fn write_file_async( &self, path: &Path, data: &[u8], ) -> impl Future<Output = Result<()>> + Send

Async version of write_file

Source

fn metadata_async( &self, path: &Path, ) -> impl Future<Output = Result<FileMetadata>> + Send

Async version of metadata

Source

fn exists_async(&self, path: &Path) -> impl Future<Output = bool> + Send

Async version of exists

Source

fn is_dir_async(&self, path: &Path) -> impl Future<Output = Result<bool>> + Send

Async version of is_dir

Source

fn is_file_async( &self, path: &Path, ) -> impl Future<Output = Result<bool>> + Send

Async version of is_file

Source

fn read_dir_async( &self, path: &Path, ) -> impl Future<Output = Result<Vec<DirEntry>>> + Send

Async version of read_dir

Source

fn canonicalize_async( &self, path: &Path, ) -> impl Future<Output = Result<PathBuf>> + Send

Async version of canonicalize

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§

Source§

impl<T: FileSystem> FileSystemExt for T

Blanket implementation: all FileSystem types automatically get async methods