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
sourceimpl 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 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
sourceimpl Deref for SyncFile
impl Deref for SyncFile
type Target = RandomAccessFile
type Target = RandomAccessFile
The resulting type after dereferencing.
sourcefn deref(&self) -> &RandomAccessFile
fn deref(&self) -> &RandomAccessFile
Dereferences the value.
sourceimpl From<RandomAccessFile> for SyncFile
impl From<RandomAccessFile> for SyncFile
sourcefn from(file: RandomAccessFile) -> SyncFileⓘNotable traits for SyncFileimpl Read for SyncFileimpl Write for SyncFile
fn from(file: RandomAccessFile) -> SyncFileⓘNotable traits for SyncFileimpl Read for SyncFileimpl Write for SyncFile
Creates a new SyncFile
from an open RandomAccessFile
.
The cursor starts at the beginning of the file.
sourceimpl FromRawFd for SyncFile
impl FromRawFd for SyncFile
sourceunsafe fn from_raw_fd(fd: RawFd) -> Self
unsafe fn from_raw_fd(fd: RawFd) -> Self
Constructs a new instance of Self
from the given raw file
descriptor. Read more
sourceimpl Read for SyncFile
impl Read for SyncFile
sourcefn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
Read the exact number of bytes required to fill buf
. Read more
1.36.0 · sourcefn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
Like read
, except that it reads into a slice of buffers. Read more
sourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
1.0.0 · sourcefn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
Read all bytes until EOF in this source, placing them into buf
. Read more
1.0.0 · sourcefn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Read all bytes until EOF in this source, appending them to buf
. Read more
sourcefn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
read_buf
)Pull some bytes from this source into the specified buffer. Read more
sourcefn read_buf_exact(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
read_buf
)Read the exact number of bytes required to fill buf
. Read more
1.0.0 · sourcefn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Creates a “by reference” adaptor for this instance of Read
. Read more
sourceimpl Seek for SyncFile
impl Seek for SyncFile
sourcefn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
Seek to an offset, in bytes, in a stream. Read more
sourcefn stream_position(&mut self) -> Result<u64>
fn stream_position(&mut self) -> Result<u64>
Returns the current seek position from the start of the stream. Read more
sourceimpl Write for SyncFile
impl Write for SyncFile
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. Read more
sourcefn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
Attempts to write an entire buffer into this writer. Read more
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
sourcefn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Auto Trait Implementations
impl RefUnwindSafe for SyncFile
impl Send for SyncFile
impl Sync for SyncFile
impl Unpin for SyncFile
impl UnwindSafe for SyncFile
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more