pub struct File { /* private fields */ }
Expand description
Wrapper around std::fs::File
which adds more helpful
information to all errors.
Implementations§
Source§impl File
Wrappers for methods from std::fs::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 create_new<P>(path: P) -> Result<Self, Error>
pub fn create_new<P>(path: P) -> Result<Self, Error>
Opens a file in read-write mode.
Wrapper for File::create_new
.
Sourcepub fn options() -> OpenOptions
pub fn options() -> OpenOptions
Returns a new OpenOptions
object.
Wrapper for File::options
.
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
Methods added by fs-err that are not available on
std::fs::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 AsHandle for File
impl AsHandle for File
Source§fn as_handle(&self) -> BorrowedHandle<'_>
fn as_handle(&self) -> BorrowedHandle<'_>
Source§impl AsRawHandle for File
impl AsRawHandle for File
Source§fn as_raw_handle(&self) -> RawHandle
fn as_raw_handle(&self) -> RawHandle
Source§impl From<File> for OwnedHandle
impl From<File> for OwnedHandle
Source§impl IntoRawHandle for File
impl IntoRawHandle for File
Source§fn into_raw_handle(self) -> RawHandle
fn into_raw_handle(self) -> RawHandle
Source§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 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 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 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 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
)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
)