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>where
P: Into<PathBuf>,
pub fn open<P>(path: P) -> Result<Self, Error>where P: Into<PathBuf>,
Attempts to open a file in read-only mode.
Wrapper for File::open
.
sourcepub fn create<P>(path: P) -> Result<Self, Error>where
P: Into<PathBuf>,
pub fn create<P>(path: P) -> Result<Self, Error>where P: Into<PathBuf>,
Opens a file in write-only mode.
Wrapper for File::create
.
sourcepub fn from_options<P>(path: P, options: &OpenOptions) -> Result<Self, Error>where
P: Into<PathBuf>,
👎Deprecated: use fs_err::OpenOptions::open instead
pub fn from_options<P>(path: P, options: &OpenOptions) -> Result<Self, Error>where P: Into<PathBuf>,
Wrapper for OpenOptions::open
.
This takes &std::fs::OpenOptions
,
not crate::OpenOptions
.
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) -> Selfwhere
P: Into<PathBuf>,
pub fn from_parts<P>(file: File, path: P) -> Selfwhere P: Into<PathBuf>,
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
Available on crate feature io_safety
only.
impl AsHandle for File
io_safety
only.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
Available on crate feature io_safety
only.
impl From<File> for OwnedHandle
io_safety
only.source§impl IntoRawHandle for File
impl IntoRawHandle for File
source§fn into_raw_handle(self) -> RawHandle
fn into_raw_handle(self) -> RawHandle
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
)