Skip to main content

FileWriter

Struct FileWriter 

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

Type-erased provider write session explicitly 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::Output;

let mut writer = filesystem.open_writer(&Path::parse("/new-report")?, WriteOptions::default())?;
writer.write_fully(b"report")?;
let outcome = writer.commit()?;
assert_eq!(Some(6), outcome.bytes_written());
assert_eq!(WriterState::Committed, writer.state());

Implementations§

Source§

impl FileWriter

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(&mut self) -> Result<WriteOutcome, WriteFailure>

Publishes bytes accepted by this session.

This method borrows rather than consumes the writer. The provider’s typed failure determines whether retry remains safe or only explicit cleanup is available.

§Returns

Actual publication method and atomicity on success.

§Errors

Returns FsErrorKind::InvalidState after commit or abort, or the provider publication error.

Source

pub fn abort(&mut self) -> FsResult<WriteAbortOutcome>

Aborts this writer and releases provider staging resources.

Abort is allowed while open and after every failed commit. Successful cleanup does not imply that an already-published target was rolled back. Every Ok outcome confirms cleanup; Indeterminate means only that the destination publication state remains unknown. An indeterminate abort disables automatic drop cleanup so the caller can inspect provider state before choosing a recovery action.

§Returns

Provider-confirmed destination publication state after cleanup.

§Errors

Returns FsErrorKind::InvalidState after commit or a previous abort, or returns the provider cleanup error while retaining the session.

Trait Implementations§

Source§

impl Debug for FileWriter

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 FileWriter

Source§

fn drop(&mut self)

Aborts provider work when this writer still owns a live session.

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

impl Output for FileWriter

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 write_unchecked( &mut self, input: &[u8], index: usize, count: usize, ) -> IoResult<usize>

Writes a range and records provider progress or uncertainty.

§Safety

index and count must identify a valid range within input.

§Parameters
  • 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 flush(&mut self) -> IoResult<()>

Flushes the provider session and marks it indeterminate on failure.

Source§

fn into_std_write(self) -> StdWrite<Self> ⓘ
where Self: Sized + ByteOutput,

Converts this byte output into a standard library writer. Read more
Source§

fn write(&mut self, input: &[Self::Item]) -> Result<usize, Error>

Writes items from the full input slice. Read more
Source§

unsafe fn write_fully_unchecked( &mut self, input: &[Self::Item], index: usize, count: usize, ) -> Result<(), Error>

Writes all items from an indexed input range. Read more
Source§

fn write_fully(&mut self, input: &[Self::Item]) -> Result<(), Error>

Writes all items from the full input slice. Read more
Source§

fn write_vectored(&mut self, buffers: &[&[Self::Item]]) -> Result<usize, Error>

Writes items from multiple buffers in list order. 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> 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> ByteOutput for T
where T: Output<Item = u8> + ?Sized,

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.