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 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. 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 the value using the given formatter. Read more
Source§

impl Drop for FileWriter

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
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 item type written to this output.
Source§

fn is_buffered(&self) -> bool

Returns whether this output already buffers items internally. Read more
Source§

unsafe fn write_unchecked( &mut self, input: &[u8], index: usize, count: usize, ) -> IoResult<usize>

Writes items from an indexed input range without checking the range. Read more
Source§

fn flush(&mut self) -> IoResult<()>

Flushes any internally buffered items. 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

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> 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.