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
Source§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
)