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§
Sourcefn read_file_async(
&self,
path: &Path,
) -> impl Future<Output = Result<Vec<u8>>> + Send
fn read_file_async( &self, path: &Path, ) -> impl Future<Output = Result<Vec<u8>>> + Send
Async version of read_file
Sourcefn read_range_async(
&self,
path: &Path,
offset: u64,
len: usize,
) -> 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
Async version of read_range
Sourcefn count_line_feeds_in_range_async(
&self,
path: &Path,
offset: u64,
len: usize,
) -> impl Future<Output = Result<usize>> + Send
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
Sourcefn write_file_async(
&self,
path: &Path,
data: &[u8],
) -> impl Future<Output = Result<()>> + Send
fn write_file_async( &self, path: &Path, data: &[u8], ) -> impl Future<Output = Result<()>> + Send
Async version of write_file
Sourcefn metadata_async(
&self,
path: &Path,
) -> impl Future<Output = Result<FileMetadata>> + Send
fn metadata_async( &self, path: &Path, ) -> impl Future<Output = Result<FileMetadata>> + Send
Async version of metadata
Sourcefn exists_async(&self, path: &Path) -> impl Future<Output = bool> + Send
fn exists_async(&self, path: &Path) -> impl Future<Output = bool> + Send
Async version of exists
Sourcefn is_dir_async(&self, path: &Path) -> impl Future<Output = Result<bool>> + Send
fn is_dir_async(&self, path: &Path) -> impl Future<Output = Result<bool>> + Send
Async version of is_dir
Sourcefn is_file_async(
&self,
path: &Path,
) -> impl Future<Output = Result<bool>> + Send
fn is_file_async( &self, path: &Path, ) -> impl Future<Output = Result<bool>> + Send
Async version of is_file
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§
impl<T: FileSystem> FileSystemExt for T
Blanket implementation: all FileSystem types automatically get async methods