pub struct File { /* private fields */ }Expand description
Async file handle supporting stateful streams and positioned reads.
Implementations§
Source§impl File
impl File
Sourcepub async fn open<P>(path: P) -> Result<File, Error>
pub async fn open<P>(path: P) -> Result<File, Error>
Open a file with default options (read-only)
Sourcepub async fn create<P>(path: P) -> Result<File, Error>
pub async fn create<P>(path: P) -> Result<File, Error>
Create a new file for writing (truncates if exists)
Sourcepub async fn open_with_options<P>(
path: P,
options: FileOpenOptions,
) -> Result<File, Error>
pub async fn open_with_options<P>( path: P, options: FileOpenOptions, ) -> Result<File, Error>
Open a file with custom options
Sourcepub async fn read_to_string(&mut self) -> Result<String, Error>
pub async fn read_to_string(&mut self) -> Result<String, Error>
Read entire file contents into a string
Sourcepub async fn read_to_end(&mut self) -> Result<Vec<u8>, Error>
pub async fn read_to_end(&mut self) -> Result<Vec<u8>, Error>
Read entire file contents into a byte vector
Sourcepub async fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
pub async fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Write all data from a buffer.
The whole buffer is one pool job: once submitted, it is written in full even if this future is dropped.
Sourcepub async fn sync_all(&mut self) -> Result<(), Error>
pub async fn sync_all(&mut self) -> Result<(), Error>
Synchronize all data and metadata to disk
Sourcepub async fn sync_data(&mut self) -> Result<(), Error>
pub async fn sync_data(&mut self) -> Result<(), Error>
Synchronize data (but not metadata) to disk
Sourcepub async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
pub async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
Seek to a specific position in the file
Sourcepub async fn stream_position(&mut self) -> Result<u64, Error>
pub async fn stream_position(&mut self) -> Result<u64, Error>
Get current position in the file
Trait Implementations§
Source§impl AsyncLength for File
impl AsyncLength for File
Source§impl AsyncReadAt for File
impl AsyncReadAt for File
Source§impl AsyncWrite for File
impl AsyncWrite for File
Source§fn poll_write(
self: Pin<&mut File>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize, Error>>
fn poll_write( self: Pin<&mut File>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>
Attempt to write bytes from the buffer to the destination.
Source§fn poll_flush(
self: Pin<&mut File>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_flush( self: Pin<&mut File>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>
Attempt to flush pending writes.
Source§fn poll_shutdown(
self: Pin<&mut File>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_shutdown( self: Pin<&mut File>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>
Attempt to close/shutdown the write side of the stream.
Source§fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, Error>>
fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>
Attempt to write bytes from several buffers in one operation. Read more
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
Whether
poll_write_vectored is cheaper
than one poll_write per buffer.Auto Trait Implementations§
impl !RefUnwindSafe for File
impl !UnwindSafe for File
impl Freeze for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnsafeUnpin for File
Blanket Implementations§
Source§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
Source§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
Source§fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> ⓘwhere
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> ⓘwhere
Self: Unpin,
Write some bytes asynchronously.
Source§fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self> ⓘwhere
Self: Unpin,
fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self> ⓘwhere
Self: Unpin,
Write all bytes asynchronously.
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
Mutably borrows from an owned value. Read more