pub struct File { /* private fields */ }
Expand description
Wrapper around std::fs::File
which adds more helpful
information to all errors.
Implementations§
source§impl File
impl File
Wrappers for methods from std::fs::File
.
sourcepub fn open<P>(path: P) -> Result<Self, Error>
pub fn open<P>(path: P) -> Result<Self, Error>
Attempts to open a file in read-only mode.
Wrapper for File::open
.
sourcepub fn create<P>(path: P) -> Result<Self, Error>
pub fn create<P>(path: P) -> Result<Self, Error>
Opens a file in write-only mode.
Wrapper for File::create
.
sourcepub fn sync_all(&self) -> Result<(), Error>
pub fn sync_all(&self) -> Result<(), Error>
Attempts to sync all OS-internal metadata to disk.
Wrapper for File::sync_all
.
sourcepub fn sync_data(&self) -> Result<(), Error>
pub fn sync_data(&self) -> Result<(), Error>
This function is similar to [sync_all
], except that it might not synchronize file metadata to the filesystem.
Wrapper for File::sync_data
.
sourcepub fn set_len(&self, size: u64) -> Result<(), Error>
pub fn set_len(&self, size: u64) -> Result<(), Error>
Truncates or extends the underlying file, updating the size of this file to become size
.
Wrapper for File::set_len
.
sourcepub fn metadata(&self) -> Result<Metadata, Error>
pub fn metadata(&self) -> Result<Metadata, Error>
Queries metadata about the underlying file.
Wrapper for File::metadata
.
sourcepub fn try_clone(&self) -> Result<Self, Error>
pub fn try_clone(&self) -> Result<Self, Error>
Creates a new File
instance that shares the same underlying file handle as the
existing File
instance. Reads, writes, and seeks will affect both File
instances simultaneously.
Wrapper for File::try_clone
.
sourcepub fn set_permissions(&self, perm: Permissions) -> Result<(), Error>
pub fn set_permissions(&self, perm: Permissions) -> Result<(), Error>
Changes the permissions on the underlying file.
Wrapper for File::set_permissions
.
source§impl File
impl File
Methods added by fs-err that are not available on
std::fs::File
.
sourcepub fn from_parts<P>(file: File, path: P) -> Self
pub fn from_parts<P>(file: File, path: P) -> Self
Creates a File
from a raw file and its path.
sourcepub fn into_parts(self) -> (File, PathBuf)
pub fn into_parts(self) -> (File, PathBuf)
Extract the raw file and its path from this File
sourcepub fn file(&self) -> &File
pub fn file(&self) -> &File
Returns a reference to the underlying std::fs::File
.
sourcepub fn file_mut(&mut self) -> &mut File
pub fn file_mut(&mut self) -> &mut File
Returns a mutable reference to the underlying std::fs::File
.
Trait Implementations§
source§impl AsFd for File
impl AsFd for File
source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
source§impl IntoRawFd for File
impl IntoRawFd for File
source§fn into_raw_fd(self) -> RawFd
fn into_raw_fd(self) -> RawFd
source§impl<'a> Read for &'a File
impl<'a> Read for &'a File
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresource§impl Read for File
impl Read for File
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresource§impl<'a> Seek for &'a File
impl<'a> Seek for &'a File
source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len
)source§impl Seek for File
impl Seek for File
source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len
)source§impl<'a> Write for &'a File
impl<'a> Write for &'a File
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)source§impl Write for File
impl Write for File
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)