pub trait WriteSupportingVfs<'vfs>: Vfs<'vfs> {
type WFile: Write + 'vfs;
// Required methods
fn open_write(
self: Pin<&Self>,
path: &Self::Path,
) -> VfsResult<Self::WFile, Self>;
fn remove_dir_all(
self: Pin<&Self>,
path: &Self::Path,
) -> VfsResult<(), Self>;
fn create_dir(self: Pin<&Self>, path: &Self::Path) -> VfsResult<(), Self>;
fn create_dir_all(
self: Pin<&Self>,
path: &Self::Path,
) -> VfsResult<(), Self>;
// Provided methods
fn write(
self: Pin<&Self>,
path: &Self::Path,
data: &[u8],
) -> VfsResult<(), Self> { ... }
fn create_parent_dir(
self: Pin<&Self>,
path: &Self::Path,
) -> VfsResult<(), Self> { ... }
}Expand description
A virtual file system that supports writing operations.
This trait extends the Vfs trait with methods for writing files and creating/removing directories.
See the module-level documentation for more details.
Required Associated Types§
Sourcetype WFile: Write + 'vfs
type WFile: Write + 'vfs
The type of the file returned by the open_write method.
This allows us to write a file in chunks, which might be required for some certain file formats.
If this type additionally implements Seek, then, similarly to VfsWithSeekRead,
the VfsWithSeekWrite trait will be automatically implemented for this WriteSupportingVfs.
See VfsWithSeekWrite for more.
Required Methods§
Sourcefn open_write(
self: Pin<&Self>,
path: &Self::Path,
) -> VfsResult<Self::WFile, Self>
fn open_write( self: Pin<&Self>, path: &Self::Path, ) -> VfsResult<Self::WFile, Self>
Opens a file for writing, at the specified path.
This method will create the file if it does not exist, or truncate it if it does.
Note that this does not create parent directories, that should happen separately in the calling code,
which can be done using the create_parent_dir method.
Sourcefn remove_dir_all(self: Pin<&Self>, path: &Self::Path) -> VfsResult<(), Self>
fn remove_dir_all(self: Pin<&Self>, path: &Self::Path) -> VfsResult<(), Self>
Removes a directory and all its contents.
This method should remove the directory at the specified path, along with all its contents.
Provided Methods§
Sourcefn write(
self: Pin<&Self>,
path: &Self::Path,
data: &[u8],
) -> VfsResult<(), Self>
fn write( self: Pin<&Self>, path: &Self::Path, data: &[u8], ) -> VfsResult<(), Self>
Writes the data to a file, to the specified path.
Similarly to open_write, this method will not create parent directories.
The parent directories should be created separately in the calling code, which can be done using
the create_parent_dir method.
Sourcefn create_parent_dir(self: Pin<&Self>, path: &Self::Path) -> VfsResult<(), Self>
fn create_parent_dir(self: Pin<&Self>, path: &Self::Path) -> VfsResult<(), Self>
Creates the parent directory for the specified path, if it does not exist.
This is a convenience method that can be used before writing a file, to ensure that the parent directory exists. If the parent directory already exists, this method does nothing. If the path has no parent, this method does nothing.
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.