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.
SyncFile
s 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 AsFd for SyncFile
impl AsFd for SyncFile
source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
source§impl Deref for SyncFile
impl Deref for SyncFile
§type Target = RandomAccessFile
type Target = RandomAccessFile
source§fn deref(&self) -> &RandomAccessFile
fn deref(&self) -> &RandomAccessFile
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 FromRawFd for SyncFile
impl FromRawFd for SyncFile
source§unsafe fn from_raw_fd(fd: RawFd) -> Self
unsafe fn from_raw_fd(fd: RawFd) -> Self
Self
from the given raw file
descriptor. Read moresource§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 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 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 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
)