pub struct File { /* private fields */ }Expand description
An object providing access to an open file on the filesystem.
Files are automatically closed when they go out of scope. Errors detected
on closing are ignored by the implementation of Drop.
Use fs::close to close explicitly and observe close errors.
Implementations§
Source§impl File
impl File
Sourcepub async fn read(&mut self, buffer: &mut [u8]) -> Result<usize>
pub async fn read(&mut self, buffer: &mut [u8]) -> Result<usize>
Reads bytes from the file into the provided buffer.
Sourcepub async fn write(&mut self, buffer: &[u8]) -> Result<usize>
pub async fn write(&mut self, buffer: &[u8]) -> Result<usize>
Writes bytes from the provided buffer to the file.
Sourcepub async fn read_vectored(
&mut self,
buffers: &mut [IoSliceMut<'_>],
) -> Result<usize>
pub async fn read_vectored( &mut self, buffers: &mut [IoSliceMut<'_>], ) -> Result<usize>
Reads from multiple buffers.
Sourcepub async fn write_vectored(&mut self, buffers: &[IoSlice<'_>]) -> Result<usize>
pub async fn write_vectored(&mut self, buffers: &[IoSlice<'_>]) -> Result<usize>
Writes from multiple buffers.
Sourcepub async fn sync_all(&mut self) -> Result<()>
pub async fn sync_all(&mut self) -> Result<()>
Attempts to sync all OS-internal file content and metadata to disk.
This function will attempt to ensure that all in-memory data reaches the filesystem before returning.
Sourcepub async fn sync_data(&mut self) -> Result<()>
pub async fn sync_data(&mut self) -> Result<()>
This function is similar to sync_all, except that it might not
synchronize file metadata to the filesystem.
This is intended for use cases that must synchronize content, but don’t need the metadata on disk. The goal of this method is to reduce disk operations.
Note that some platforms may simply implement this in terms of
sync_all.
Sourcepub async fn set_len(&mut self, size: u64) -> Result<()>
pub async fn set_len(&mut self, size: u64) -> Result<()>
Changes the size of the file.
Truncates or extends the underlying file, updating the size of this file to become size. If the size is less than the current file’s size, then the file will be shrunk. If it is greater than the current file’s size, then the file will be extended to size and have all of the intermediate data filled in with 0s.
Sourcepub fn read_sync(&mut self, buffer: &mut [u8]) -> Result<usize>
pub fn read_sync(&mut self, buffer: &mut [u8]) -> Result<usize>
Synchronous filesystem operation read_sync.
Sourcepub fn write_sync(&mut self, buffer: &[u8]) -> Result<usize>
pub fn write_sync(&mut self, buffer: &[u8]) -> Result<usize>
Synchronous filesystem operation write_sync.
Sourcepub fn read_vectored_sync(
&mut self,
buffers: &mut [IoSliceMut<'_>],
) -> Result<usize>
pub fn read_vectored_sync( &mut self, buffers: &mut [IoSliceMut<'_>], ) -> Result<usize>
Synchronous filesystem operation read_vectored_sync.
Sourcepub fn write_vectored_sync(&mut self, buffers: &[IoSlice<'_>]) -> Result<usize>
pub fn write_vectored_sync(&mut self, buffers: &[IoSlice<'_>]) -> Result<usize>
Synchronous filesystem operation write_vectored_sync.
Sourcepub fn sync_all_sync(&mut self) -> Result<()>
pub fn sync_all_sync(&mut self) -> Result<()>
Synchronous filesystem operation sync_all_sync.
Sourcepub fn sync_data_sync(&mut self) -> Result<()>
pub fn sync_data_sync(&mut self) -> Result<()>
Synchronous filesystem operation sync_data_sync.
Sourcepub fn set_len_sync(&mut self, size: u64) -> Result<()>
pub fn set_len_sync(&mut self, size: u64) -> Result<()>
Synchronous filesystem operation set_len_sync.
Sourcepub async fn fchown(&self, uid: u32, gid: u32) -> Result<()>
pub async fn fchown(&self, uid: u32, gid: u32) -> Result<()>
Changes the owner and group of the open file.
Sourcepub async fn futimes(&self, atime: SystemTime, mtime: SystemTime) -> Result<()>
pub async fn futimes(&self, atime: SystemTime, mtime: SystemTime) -> Result<()>
Changes the access and modification times of the open file.
Sourcepub fn metadata_sync(&self) -> Result<Metadata>
pub fn metadata_sync(&self) -> Result<Metadata>
Synchronous filesystem operation metadata_sync.
Sourcepub fn fchmod_sync(&self, mode: u32) -> Result<()>
pub fn fchmod_sync(&self, mode: u32) -> Result<()>
Synchronous filesystem operation fchmod_sync.
Sourcepub fn fchown_sync(&self, uid: u32, gid: u32) -> Result<()>
pub fn fchown_sync(&self, uid: u32, gid: u32) -> Result<()>
Synchronous filesystem operation fchown_sync.
Sourcepub fn futimes_sync(&self, atime: SystemTime, mtime: SystemTime) -> Result<()>
pub fn futimes_sync(&self, atime: SystemTime, mtime: SystemTime) -> Result<()>
Synchronous filesystem operation futimes_sync.