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§

source§

impl SharedFile<TempFile>

source

pub async fn from_existing( path: PathBuf, ownership: Ownership ) -> Result<SharedFile<TempFile>, Error>

Available on crate feature 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.
source§

impl<T> SharedFile<T>where T: SharedFileType<Type = T>,

source

pub fn new() -> Result<SharedFile<T>, T::Error>where T: NewFile<Target = T>,

Synchronously creates a new temporary file.

source

pub async fn new_async() -> Result<SharedFile<T>, T::Error>where T: AsyncNewFile<Target = T>,

Asynchronously creates a new temporary file.

source

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.

source

pub async fn reader(&self) -> Result<SharedFileReader<T::Type>, T::OpenError>

Creates a reader for the file.

Trait Implementations§

source§

impl<T: Debug> Debug for SharedFile<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Default for SharedFile<T>where T: Default,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T> FilePath for SharedFile<T>where T: FilePath,

source§

fn file_path(&self) -> &PathBuf

Obtains the path of the temporary file.
source§

impl<T> From<T> for SharedFile<T>

source§

fn from(value: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for SharedFile<T>where T: RefUnwindSafe,

§

impl<T> Send for SharedFile<T>where T: Send + Sync,

§

impl<T> Sync for SharedFile<T>where T: Send + Sync,

§

impl<T> Unpin for SharedFile<T>

§

impl<T> UnwindSafe for SharedFile<T>where T: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.