Struct shared_files::SharedFile
source · pub struct SharedFile<T> { /* private fields */ }
Expand description
A file with shared read/write access for in-process file sharing.
Writer / Reader Synchronization
Since this wrapper takes over control of the write operation, readers
will only be woken up on a call to SharedFileWriter::sync_data
,
SharedFileWriter::sync_all
or [SharedFileWriter::flush
]. This is to
ensure that data is actually written to the underlying buffer before
the readers attempt to read it back.
Writer Finalization
When a writer is dropped, it will move the state of the SharedFile
to
[WriteState::Completed
]. It is important to note that drop is not asynchronous
and therefore no flush to disk can be performed on the wrapped file.
⚠️ User code must make sure to manually sync to disk before dropping the writer.
Implementations§
sourcepub async fn from_existing(
path: PathBuf,
ownership: Ownership
) -> Result<SharedFile<TempFile>, Error>
Available on crate feature async-tempfile
only.
pub async fn from_existing( path: PathBuf, ownership: Ownership ) -> Result<SharedFile<TempFile>, Error>
async-tempfile
only.Wraps a new instance of this type around an existing file. This is a convencience
wrapper around TempFile::from_existing
and SharedFile::from
.
If ownership
is set to Ownership::Borrowed
, this method does not take ownership of
the file, i.e. the file will not be deleted when the instance is dropped.
Arguments
path
- The path of the file to wrap.ownership
- The ownership of the file.
sourcepub fn new() -> Result<SharedFile<T>, T::Error>where
T: NewFile<Target = T>,
pub fn new() -> Result<SharedFile<T>, T::Error>where T: NewFile<Target = T>,
Synchronously creates a new temporary file.
sourcepub async fn new_async() -> Result<SharedFile<T>, T::Error>where
T: AsyncNewFile<Target = T>,
pub async fn new_async() -> Result<SharedFile<T>, T::Error>where T: AsyncNewFile<Target = T>,
Asynchronously creates a new temporary file.
sourcepub async fn writer(&self) -> Result<SharedFileWriter<T::Type>, T::OpenError>
pub async fn writer(&self) -> Result<SharedFileWriter<T::Type>, T::OpenError>
Creates a writer for the file.
Reader / writer Synchronization
Since this wrapper takes over control of the write operation, readers
will only be woken up on a call to SharedFileWriter::sync_data
,
SharedFileWriter::sync_all
or [SharedFileWriter::flush
]. This is to
ensure that data is actually written to the underlying buffer before
the readers attempt to read it back.
Writer finalization
⚠️ User code must make sure to manually sync to disk before dropping the writer.
When a writer is dropped, it will move the state of the SharedFile
to
[WriteState::Completed
]. It is important to note that drop is not asynchronous
and therefore no flush to disk can be performed on the wrapped file.
One writer at a time
This operation can result in odd behavior if the file is accessed multiple times for write access. User code must make sure that only one meaningful write is performed at the same time.