pub struct File { /* private fields */ }
Expand description
A reference to an open file on the filesystem.
An instance of a File
can be read and/or written depending on what options
it was opened with. The File
type provides positional read and write
operations. The file does not maintain an internal cursor. The caller is
required to specify an offset when issuing an operation.
Implementations§
Source§impl File
impl File
Sourcepub async fn open(path: impl AsRef<Path>) -> Result<Self>
pub async fn open(path: impl AsRef<Path>) -> Result<Self>
Attempts to open a file in read-only mode.
See the OpenOptions::open
method for more details.
Sourcepub async fn create(path: impl AsRef<Path>) -> Result<Self>
pub async fn create(path: impl AsRef<Path>) -> Result<Self>
Opens a file in write-only mode.
This function will create a file if it does not exist, and will truncate it if it does.
See the OpenOptions::open
function for more details.
Sourcepub fn close(self) -> impl Future<Output = Result<()>>
pub fn close(self) -> impl Future<Output = Result<()>>
Close the file. If the returned future is dropped before polling, the file won’t be closed.
Sourcepub async fn metadata(&self) -> Result<Metadata>
Available on Unix only.
pub async fn metadata(&self) -> Result<Metadata>
Queries metadata about the underlying file.
Sourcepub async fn set_permissions(&self, perm: Permissions) -> Result<()>
Available on Unix only.
pub async fn set_permissions(&self, perm: Permissions) -> Result<()>
Changes the permissions on the underlying file.
Sourcepub async fn sync_all(&self) -> Result<()>
pub async fn sync_all(&self) -> Result<()>
Attempts to sync all OS-internal metadata to disk.
This function will attempt to ensure that all in-memory data reaches the filesystem before returning.
Sourcepub async fn sync_data(&self) -> Result<()>
pub async fn sync_data(&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
.
Trait Implementations§
Source§impl AsyncReadAt for File
impl AsyncReadAt for File
Source§async fn read_at<T: IoBufMut>(&self, buffer: T, pos: u64) -> BufResult<usize, T>
async fn read_at<T: IoBufMut>(&self, buffer: T, pos: u64) -> BufResult<usize, T>
AsyncRead::read
, except that it reads at a specified position.Source§async fn read_vectored_at<T: IoVectoredBufMut>(
&self,
buffer: T,
pos: u64,
) -> BufResult<usize, T>
async fn read_vectored_at<T: IoVectoredBufMut>( &self, buffer: T, pos: u64, ) -> BufResult<usize, T>
AsyncRead::read_vectored
, except that it reads at a specified
position.Source§impl AsyncWriteAt for &File
impl AsyncWriteAt for &File
Source§async fn write_at<T: IoBuf>(
&mut self,
buffer: T,
pos: u64,
) -> BufResult<usize, T>
async fn write_at<T: IoBuf>( &mut self, buffer: T, pos: u64, ) -> BufResult<usize, T>
AsyncWrite::write
, except that it writes at a specified
position.Source§async fn write_vectored_at<T: IoVectoredBuf>(
&mut self,
buffer: T,
pos: u64,
) -> BufResult<usize, T>
async fn write_vectored_at<T: IoVectoredBuf>( &mut self, buffer: T, pos: u64, ) -> BufResult<usize, T>
AsyncWrite::write_vectored
, except that it writes at a
specified position.Source§impl AsyncWriteAt for File
impl AsyncWriteAt for File
Source§async fn write_at<T: IoBuf>(&mut self, buf: T, pos: u64) -> BufResult<usize, T>
async fn write_at<T: IoBuf>(&mut self, buf: T, pos: u64) -> BufResult<usize, T>
AsyncWrite::write
, except that it writes at a specified
position.Source§async fn write_vectored_at<T: IoVectoredBuf>(
&mut self,
buf: T,
pos: u64,
) -> BufResult<usize, T>
async fn write_vectored_at<T: IoVectoredBuf>( &mut self, buf: T, pos: u64, ) -> BufResult<usize, T>
AsyncWrite::write_vectored
, except that it writes at a
specified position.Source§impl FromRawFd for File
Available on Unix only.
impl FromRawFd for File
Source§unsafe fn from_raw_fd(fd: RawFd) -> Self
unsafe fn from_raw_fd(fd: RawFd) -> Self
Self
from the given raw file
descriptor. Read moreSharedFd
.Auto Trait Implementations§
impl Freeze for File
impl RefUnwindSafe for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnwindSafe for File
Blanket Implementations§
Source§impl<A> AsyncReadAtExt for Awhere
A: AsyncReadAt + ?Sized,
impl<A> AsyncReadAtExt for Awhere
A: AsyncReadAt + ?Sized,
Source§async fn read_exact_at<T>(&self, buf: T, pos: u64) -> BufResult<(), T>where
T: IoBufMut,
async fn read_exact_at<T>(&self, buf: T, pos: u64) -> BufResult<(), T>where
T: IoBufMut,
buffer
. Read moreSource§async fn read_to_end_at(
&self,
buffer: Vec<u8>,
pos: u64,
) -> BufResult<usize, Vec<u8>>
async fn read_to_end_at( &self, buffer: Vec<u8>, pos: u64, ) -> BufResult<usize, Vec<u8>>
buffer
. Read moreSource§async fn read_vectored_exact_at<T>(&self, buf: T, pos: u64) -> BufResult<(), T>where
T: IoVectoredBufMut,
async fn read_vectored_exact_at<T>(&self, buf: T, pos: u64) -> BufResult<(), T>where
T: IoVectoredBufMut,
AsyncReadExt::read_vectored_exact
, expect that it reads at a
specified position.Source§impl<A> AsyncWriteAtExt for Awhere
A: AsyncWriteAt + ?Sized,
impl<A> AsyncWriteAtExt for Awhere
A: AsyncWriteAt + ?Sized,
Source§async fn write_all_at<T>(&mut self, buf: T, pos: u64) -> BufResult<(), T>where
T: IoBuf,
async fn write_all_at<T>(&mut self, buf: T, pos: u64) -> BufResult<(), T>where
T: IoBuf,
AsyncWriteAt::write_at
, except that it tries to write the
entire contents of the buffer into this writer.Source§async fn write_vectored_all_at<T>(
&mut self,
buf: T,
pos: u64,
) -> BufResult<(), T>where
T: IoVectoredBuf,
async fn write_vectored_all_at<T>(
&mut self,
buf: T,
pos: u64,
) -> BufResult<(), T>where
T: IoVectoredBuf,
AsyncWriteAt::write_vectored_at
, expect that it tries to write
the entire contents of the buffer into this writer.