async only.Expand description
Asynchronous virtual file system traits.
These traits are similar to the ones in the vfs module, but they use
asynchronous I/O operations, and return Futures resolving to Results instead of
directly returning Results, in line with Rust’s async programming model.
These traits require the async feature to be enabled.
They are designed to be used with async runtimes like Tokio or async-std.
You should refer to the documentation of the vfs module for
more details on the individual methods, as the async versions have the same semantics,
just with async I/O.
An important difference between the VfsAsync traits and their synchronous counterparts
is that the methods take owned paths instead of references. This is because
the async methods typically need to move the path into the future, and
references would not be valid for the entire duration of the future.
§Tool specific extensions of the async VFS traits
Similarly to the synchronous VFS traits, there are also tool-specific extensions
of the async VFS traits, which are required to use certain tools with a specific
VfsAsync implementation.
We list them here for convenience, but you should refer to the documentation of the individual tools for more details.
§AtomicDir<T>
To use the AtomicDir<T> wrapper type with your async VFS implementation,
the VFS type itself must implement the VfsSupportsTemporaryDirectories trait.
See its documentation for more details.
§Images
To allow reading and writing image files using the types and traits from the
image module, the following traits need to be implemented for your
async VFS type YourVfsType:
impl<T: ImgFormat> ReadImageFromAsync<T> for YourVfsTypeto satisfy the boundT: ReadFromAsync<'vfs, YourVfsType>impl<'a> WriteImageToAsync<'a> for YourVfsTypeto satisfy the boundT: WriteToAsync<'a, YourVfsType>impl<'a> WriteImageToAsyncRef<'a, YourVfsType> for YourVfsTypeto satisfy the boundT: WriteToAsyncRef<'a, YourVfsType>
These impls are required because the image encoding and decoding operations are CPU-bound and blocking, and thus cannot be implemented in a generic way for all async VFS implementations. They need to be implemented specifically for each async VFS type.
You can see the implementations for the TokioFsVfs VFS, which use
[tokio::task::spawn_blocking] to offload the blocking operations to a separate thread pool.
Your async VFS implementation might use a different async runtime, and thus might need to use a different method to offload blocking operations, but that is the ideal approach to take.
You can of course not implement these impls, but then you will not be able to use the image encoding and decoding operations with your async VFS implementation.
Traits§
- VfsAsync
- An asynchronous virtual file system.
- VfsAsync
Ext - Extension trait for
VfsAsyncthat provides additional convenience methods. - VfsAsync
With Seek Read - Marks that the
RFiletype of thisVfsAsyncalso implementsAsyncSeek, allowing it to be used in contexts that require seeking, such as image decoding. - VfsAsync
With Seek Write - Marks that the
WFiletype of thisWriteSupportingVfsAsyncalso implementsAsyncSeek, allowing it to be used in contexts that require seeking. - Write
Supporting VfsAsync - A virtual file system that supports writing operations.
- Write
Supporting VfsAsync Ext - Extension trait for
WriteSupportingVfsAsyncthat provides additional convenience methods.