Skip to main content

File

Struct File 

Source
pub struct File { /* private fields */ }
Expand description

High-performance async file handle with native implementation

Implementations§

Source§

impl File

Source

pub async fn open<P>(path: P) -> Result<File, Error>
where P: AsRef<Path>,

Open a file with default options (read-only)

Source

pub async fn create<P>(path: P) -> Result<File, Error>
where P: AsRef<Path>,

Create a new file for writing (truncates if exists)

Source

pub async fn open_with_options<P>( path: P, options: FileOpenOptions, ) -> Result<File, Error>
where P: AsRef<Path>,

Open a file with custom options

Source

pub async fn read_to_string(&mut self) -> Result<String, Error>

Read entire file contents into a string

Source

pub async fn read_to_end(&mut self) -> Result<Vec<u8>, Error>

Read entire file contents into a byte vector

Source

pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>

Read data into a buffer

Source

pub async fn write(&mut self, buf: &[u8]) -> Result<usize, Error>

Write data from a buffer

Source

pub async fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Write all data from a buffer

Source

pub async fn write_str(&mut self, s: &str) -> Result<(), Error>

Write a string to the file

Source

pub async fn flush(&mut self) -> Result<(), Error>

Flush any buffered data to disk

Source

pub async fn sync_all(&mut self) -> Result<(), Error>

Synchronize all data and metadata to disk

Source

pub async fn sync_data(&mut self) -> Result<(), Error>

Synchronize data (but not metadata) to disk

Source

pub async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>

Seek to a specific position in the file

Source

pub async fn stream_position(&mut self) -> Result<u64, Error>

Get current position in the file

Source

pub async fn metadata(&self) -> Result<Metadata, Error>

Get file metadata

Source

pub fn path(&self) -> &Path

Get file path

Source

pub fn stats(&self) -> &FileStats

Get file statistics

Trait Implementations§

Source§

impl AsyncRead for File

Source§

fn poll_read( self: Pin<&mut File>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<Result<usize, Error>>

Attempt to read from the source into the provided buffer.
Source§

impl AsyncWrite for File

Source§

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>>

Attempt to flush pending writes.
Source§

fn poll_shutdown( self: Pin<&mut File>, _cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>

Attempt to close/shutdown the write side of the stream.

Auto Trait Implementations§

§

impl Freeze for File

§

impl RefUnwindSafe for File

§

impl Send for File

§

impl Sync for File

§

impl Unpin for File

§

impl UnsafeUnpin for File

§

impl UnwindSafe for File

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<R> AsyncReadExt for R
where R: AsyncRead + ?Sized,

Source§

fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>
where Self: Unpin,

Read some bytes asynchronously from the reader.
Source§

fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>
where Self: Unpin,

Read exactly enough bytes to fill the provided buffer.
Source§

impl<W> AsyncWriteExt for W
where W: AsyncWrite + ?Sized,

Source§

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,

Write all bytes asynchronously.
Source§

fn flush(&mut self) -> Flush<'_, Self>
where Self: Unpin,

Flush pending writes asynchronously.
Source§

fn shutdown(&mut self) -> Shutdown<'_, Self>
where Self: Unpin,

Shutdown the write side of the stream.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.