Skip to main content

File

Struct File 

Source
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

Source

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

Reads bytes from the file into the provided buffer.

Source

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

Writes bytes from the provided buffer to the file.

Source

pub async fn read_vectored( &mut self, buffers: &mut [IoSliceMut<'_>], ) -> Result<usize>

Reads from multiple buffers.

Source

pub async fn write_vectored(&mut self, buffers: &[IoSlice<'_>]) -> Result<usize>

Writes from multiple buffers.

Source

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.

Source

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.

Source

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.

Source

pub fn read_sync(&mut self, buffer: &mut [u8]) -> Result<usize>

Synchronous filesystem operation read_sync.

Source

pub fn write_sync(&mut self, buffer: &[u8]) -> Result<usize>

Synchronous filesystem operation write_sync.

Source

pub fn read_vectored_sync( &mut self, buffers: &mut [IoSliceMut<'_>], ) -> Result<usize>

Synchronous filesystem operation read_vectored_sync.

Source

pub fn write_vectored_sync(&mut self, buffers: &[IoSlice<'_>]) -> Result<usize>

Synchronous filesystem operation write_vectored_sync.

Source

pub fn sync_all_sync(&mut self) -> Result<()>

Synchronous filesystem operation sync_all_sync.

Source

pub fn sync_data_sync(&mut self) -> Result<()>

Synchronous filesystem operation sync_data_sync.

Source

pub fn set_len_sync(&mut self, size: u64) -> Result<()>

Synchronous filesystem operation set_len_sync.

Source

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

Queries metadata about the underlying file.

Source

pub async fn fchmod(&self, mode: u32) -> Result<()>

Changes the permissions of the open file.

Source

pub async fn fchown(&self, uid: u32, gid: u32) -> Result<()>

Changes the owner and group of the open file.

Source

pub async fn futimes(&self, atime: SystemTime, mtime: SystemTime) -> Result<()>

Changes the access and modification times of the open file.

Source

pub fn metadata_sync(&self) -> Result<Metadata>

Synchronous filesystem operation metadata_sync.

Source

pub fn fchmod_sync(&self, mode: u32) -> Result<()>

Synchronous filesystem operation fchmod_sync.

Source

pub fn fchown_sync(&self, uid: u32, gid: u32) -> Result<()>

Synchronous filesystem operation fchown_sync.

Source

pub fn futimes_sync(&self, atime: SystemTime, mtime: SystemTime) -> Result<()>

Synchronous filesystem operation futimes_sync.

Trait Implementations§

Source§

impl Debug for File

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for File

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !Freeze for File

§

impl !RefUnwindSafe for File

§

impl !UnwindSafe for File

§

impl Send for File

§

impl Sync for File

§

impl Unpin for File

§

impl UnsafeUnpin 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<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 = !

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

fn try_from(value: U) -> Result<T, !>

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.