pub struct SyncFile(/* private fields */);Expand description
A file wrapper that is safe to use concurrently.
This wrapper exists because std::fs::File uses a single cursor, so
reading from a file concurrently will likely produce race conditions.
SyncFiles are cheap to clone and clones use distinct cursors, so they can
be used concurrently without issues.
Implementations§
Source§impl SyncFile
impl SyncFile
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<SyncFile>
pub fn open<P: AsRef<Path>>(path: P) -> Result<SyncFile>
Attempts to open a file in read-only mode.
See File::open for details.
Sourcepub fn create<P: AsRef<Path>>(path: P) -> Result<SyncFile>
pub fn create<P: AsRef<Path>>(path: P) -> Result<SyncFile>
Opens a file in write-only mode.
See File::create for details.
Sourcepub fn offset(&self) -> u64
pub fn offset(&self) -> u64
Returns the offset used when reading the file.
This is equivalent to io::Seek::stream_position but does not use a
fallible API nor require a mutable reference.
Methods from Deref<Target = RandomAccessFile>§
Sourcepub fn sync_all(&self) -> Result<()>
pub fn sync_all(&self) -> Result<()>
Attempts to sync all OS-internal metadata to disk.
See File::sync_all for details.
Sourcepub fn sync_data(&self) -> Result<()>
pub fn sync_data(&self) -> Result<()>
This function is similar to sync_all, except that it may not
synchronize file metadata to the filesystem.
See File::sync_data for details.
Sourcepub fn set_len(&self, size: u64) -> Result<()>
pub fn set_len(&self, size: u64) -> Result<()>
Truncates or extends the underlying file, updating the size of this file
to become size.
See File::set_len for details.
Sourcepub fn metadata(&self) -> Result<Metadata>
pub fn metadata(&self) -> Result<Metadata>
Queries metadata about the underlying file.
See File::metadata for details.
Sourcepub fn try_clone(&self) -> Result<RandomAccessFile>
pub fn try_clone(&self) -> Result<RandomAccessFile>
Creates a new File instance that shares the same underlying file handle
as the existing File instance
See File::try_clone for details.
Sourcepub fn set_permissions(&self, perm: Permissions) -> Result<()>
pub fn set_permissions(&self, perm: Permissions) -> Result<()>
Changes the permissions on the underlying file.
See File::set_permissions for details.
Trait Implementations§
Source§impl AsHandle for SyncFile
Available on Windows only.
impl AsHandle for SyncFile
Source§fn as_handle(&self) -> BorrowedHandle<'_>
fn as_handle(&self) -> BorrowedHandle<'_>
Source§impl AsRawHandle for SyncFile
Available on Windows only.
impl AsRawHandle for SyncFile
Source§fn as_raw_handle(&self) -> RawHandle
fn as_raw_handle(&self) -> RawHandle
Source§impl Deref for SyncFile
impl Deref for SyncFile
Source§type Target = RandomAccessFile
type Target = RandomAccessFile
Source§fn deref(&self) -> &RandomAccessFile
fn deref(&self) -> &RandomAccessFile
Source§impl From<OwnedHandle> for SyncFile
Available on Windows only.
impl From<OwnedHandle> for SyncFile
Source§fn from(handle: OwnedHandle) -> Self
fn from(handle: OwnedHandle) -> Self
Source§impl From<RandomAccessFile> for SyncFile
impl From<RandomAccessFile> for SyncFile
Source§fn from(file: RandomAccessFile) -> SyncFile ⓘ
fn from(file: RandomAccessFile) -> SyncFile ⓘ
Creates a new SyncFile from an open RandomAccessFile.
The cursor starts at the beginning of the file.
Source§impl FromRawHandle for SyncFile
Available on Windows only.
impl FromRawHandle for SyncFile
Source§unsafe fn from_raw_handle(handle: RawHandle) -> Self
unsafe fn from_raw_handle(handle: RawHandle) -> Self
Source§impl Read for SyncFile
impl Read for SyncFile
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf. Read moreSource§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 read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf. Read moreSource§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)Source§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 ReadAt for SyncFile
impl ReadAt for SyncFile
Source§fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>
fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>
Source§fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>
fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>
Source§fn read_vectored_at(
&self,
bufs: &mut [IoSliceMut<'_>],
offset: u64,
) -> Result<usize>
fn read_vectored_at( &self, bufs: &mut [IoSliceMut<'_>], offset: u64, ) -> Result<usize>
read_at, except that it reads into a slice of buffers. Read moreSource§impl Seek for SyncFile
impl Seek for SyncFile
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
Source§fn stream_position(&mut self) -> Result<u64>
fn stream_position(&mut self) -> Result<u64>
Source§impl Write for SyncFile
impl Write for SyncFile
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
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)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)