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.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)