Skip to main content

AsyncFileWriter

Struct AsyncFileWriter 

Source
pub struct AsyncFileWriter { /* private fields */ }
Expand description

Type-erased asynchronous provider write session associated with a file.

§Examples

This example uses an isolated in-memory provider fixture.

use qubit_fs::Path;
use qubit_fs::write::WriteOptions;
use qubit_fs::write::WriterState;
use qubit_io::AsyncOutput;

let mut writer = filesystem.open_writer(&Path::parse("/report")?, WriteOptions::default()).await?;
writer.write_fully_async(b"bytes").await?;
writer.commit_async().await?;
assert_eq!(WriterState::Committed, writer.state());

Implementations§

Source§

impl AsyncFileWriter

Source

pub fn info(&self) -> &OpenedFileInfo

Returns the fixed identity and open-time metadata snapshot.

§Returns

Information captured when the writer was opened.

Source

pub const fn state(&self) -> WriterState

Returns the current lifecycle state.

§Returns

Current writer state.

Source

pub const fn has_confirmed_publication(&self) -> bool

Returns whether this writer session has confirmed publication at any time.

§Returns

true when a commit or abort outcome confirmed publication. false does not prove that publication did not occur.

Source

pub const fn cleanup_state(&self) -> RecoveryCleanupState

Returns the state of explicit provider cleanup for this session.

§Returns

The latest cleanup state, independently of publication history.

Source

pub fn commit_async( &mut self, ) -> SpiFuture<'_, Result<WriteOutcome, WriteFailure>>

Asynchronously publishes bytes accepted by this session.

A definite failure retains the open session for retry or abort. An indeterminate failure retains the session and changes its observable state to WriterState::Indeterminate. Once the returned future has been polled, dropping it before completion also makes the writer indeterminate because publication may already have started. Dropping an unpolled future leaves the writer open. Only a failure in WriteFailureState::RetryableNotPublished leaves the writer open for another explicit commit attempt. WriteFailureState::NotPublished allows only a valid abort; it does not make commit retryable.

§Returns

A future resolving to the actual publication outcome.

§Errors

The future returns WriteFailure when the provider fails publication or violates the requested atomicity, durability, or byte-count contract. The failure state records what is known about publication.

Source

pub fn abort_async(&mut self) -> SpiFuture<'_, FsResult<WriteAbortOutcome>>

Asynchronously aborts this session and its provider staging resources.

Once polled, cancellation before completion leaves the writer indeterminate. A definite provider failure restores the state from which abort was started; an indeterminate provider failure does not. Automatic drop cancellation is disabled for an indeterminate writer.

§Returns

A future resolving to the provider-confirmed destination publication state after cleanup. Every Ok confirms cleanup; Indeterminate means only that destination publication is unknown.

§Errors

The future returns an FsError when provider cleanup fails. The error includes the operation context available from the facade.

Trait Implementations§

Source§

impl AsyncOutput for AsyncFileWriter

Source§

type Item = u8

The byte unit accepted by this writer.

Source§

fn is_buffered(&self) -> bool

Reports whether the provider session buffers output before flushing.

Source§

unsafe fn poll_write_unchecked( self: Pin<&mut Self>, cx: &mut Context<'_>, input: &[u8], index: usize, count: usize, ) -> Poll<IoResult<usize>>

Polls a provider write while tracking accepted bytes and uncertainty.

§Safety

index and count must identify a valid range within input.

§Parameters
  • cx: Task context used to poll the provider session.
  • input: Input bytes containing the requested range.
  • index: Starting offset of the requested input range.
  • count: Maximum number of bytes requested from the provider.
Source§

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<IoResult<()>>

Polls the provider flush and marks the writer indeterminate on failure.

§Parameters
  • cx: Task context used to poll the provider session.
Source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, input: &[Self::Item], ) -> Poll<Result<usize, Error>>

Polls one write from the full source slice. Read more
Source§

fn write_async<'a>( &'a mut self, input: &'a [Self::Item], ) -> WriteFuture<'a, Self> ⓘ
where Self: Sized + Unpin,

Creates a future that performs one asynchronous write operation. Read more
Source§

fn write_fully_async<'a>( &'a mut self, input: &'a [Self::Item], ) -> WriteFullyFuture<'a, Self> ⓘ
where Self: Sized + Unpin,

Creates a future that writes the entire source slice. Read more
Source§

fn flush_async(&mut self) -> FlushFuture<'_, Self> ⓘ
where Self: Sized + Unpin,

Creates a future that flushes internally buffered items. Read more
Source§

impl Debug for AsyncFileWriter

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult

Formats lifecycle facts without exposing the provider session.

§Parameters
  • formatter: Formatter receiving the diagnostic representation.
Source§

impl Drop for AsyncFileWriter

Source§

fn drop(&mut self)

Requests provider cancellation when this writer still owns live work.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsyncByteOutput for T
where T: AsyncOutput<Item = u8> + ?Sized,

Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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.

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.