pub trait VirtualFile:
Debug
+ AsyncRead
+ AsyncWrite
+ AsyncSeek
+ Unpin
+ Upcastable
+ Send {
Show 15 methods
// Required methods
fn last_accessed(&self) -> u64;
fn last_modified(&self) -> u64;
fn created_time(&self) -> u64;
fn size(&self) -> u64;
fn set_len(&mut self, new_size: u64) -> Result<()>;
fn unlink(&mut self) -> Result<()>;
fn poll_read_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<usize>>;
fn poll_write_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<usize>>;
// Provided methods
fn set_times(
&mut self,
atime: Option<u64>,
mtime: Option<u64>,
) -> Result<()> { ... }
fn is_open(&self) -> bool { ... }
fn get_special_fd(&self) -> Option<u32> { ... }
fn write_from_mmap(&mut self, _offset: u64, _len: u64) -> Result<()> { ... }
fn copy_reference(
&mut self,
src: Box<dyn VirtualFile + Send + Sync + 'static>,
) -> BoxFuture<'_, Result<()>> { ... }
fn copy_from_owned_buffer(
&mut self,
src: &OwnedBuffer,
) -> BoxFuture<'_, Result<()>> { ... }
fn as_owned_buffer(&self) -> Option<OwnedBuffer> { ... }
}Expand description
This trait relies on your file closing when it goes out of scope via Drop
Required Methods§
Sourcefn last_accessed(&self) -> u64
fn last_accessed(&self) -> u64
the last time the file was accessed in nanoseconds as a UNIX timestamp
Sourcefn last_modified(&self) -> u64
fn last_modified(&self) -> u64
the last time the file was modified in nanoseconds as a UNIX timestamp
Sourcefn created_time(&self) -> u64
fn created_time(&self) -> u64
the time at which the file was created in nanoseconds as a UNIX timestamp
Sourcefn set_len(&mut self, new_size: u64) -> Result<()>
fn set_len(&mut self, new_size: u64) -> Result<()>
Change the size of the file, if the new_size is greater than the current size
the extra bytes will be allocated and zeroed
Sourcefn unlink(&mut self) -> Result<()>
fn unlink(&mut self) -> Result<()>
Remove the file from the filesystem namespace.
Existing open handles may continue to operate after this call. Backends may defer final storage reclamation until the last open handle is dropped.
Provided Methods§
Sourcefn set_times(&mut self, atime: Option<u64>, mtime: Option<u64>) -> Result<()>
fn set_times(&mut self, atime: Option<u64>, mtime: Option<u64>) -> Result<()>
sets accessed and modified time
Sourcefn is_open(&self) -> bool
fn is_open(&self) -> bool
Indicates if the file is opened or closed. This function must not block Defaults to a status of being constantly open
Sourcefn get_special_fd(&self) -> Option<u32>
fn get_special_fd(&self) -> Option<u32>
Used for “special” files such as stdin, stdout and stderr.
Always returns the same file descriptor (0, 1 or 2). Returns None
on normal files
Sourcefn write_from_mmap(&mut self, _offset: u64, _len: u64) -> Result<()>
fn write_from_mmap(&mut self, _offset: u64, _len: u64) -> Result<()>
Writes to this file using an mmap offset and reference (this method only works for mmap optimized file systems)
Sourcefn copy_reference(
&mut self,
src: Box<dyn VirtualFile + Send + Sync + 'static>,
) -> BoxFuture<'_, Result<()>>
fn copy_reference( &mut self, src: Box<dyn VirtualFile + Send + Sync + 'static>, ) -> BoxFuture<'_, Result<()>>
This method will copy a file from a source to this destination where the default is to do a straight byte copy however file system implementors may optimize this to do a zero copy
Sourcefn copy_from_owned_buffer(
&mut self,
src: &OwnedBuffer,
) -> BoxFuture<'_, Result<()>>
fn copy_from_owned_buffer( &mut self, src: &OwnedBuffer, ) -> BoxFuture<'_, Result<()>>
This method will copy a file from a source to this destination where the default is to do a straight byte copy however file system implementors may optimize this to cheaply clone and store the OwnedBuffer directly
Sourcefn as_owned_buffer(&self) -> Option<OwnedBuffer>
fn as_owned_buffer(&self) -> Option<OwnedBuffer>
Get the full contents of this file as an [OwnedBuffer].
NOTE: Only implement this if the file is already available in-memory and can be cloned cheaply!
Allows consumers to do zero-copy cloning of the underlying data.