Skip to main content

FileWriteOp

Struct FileWriteOp 

Source
pub struct FileWriteOp<'a> { /* private fields */ }
Expand description

One item being written: a tensor, the header, or the footer.

Borrowing both the core and the caller’s payloads for its lifetime is what enforces ADR-041 § 3’s ownership rule in the type system — the core cannot hold a payload pointer after the operation ends, because the operation is what holds them.

§Examples

See FileWriterCore.

Implementations§

Source§

impl FileWriteOp<'_>

Source

pub fn step(&mut self) -> Result<WriteStep>

Advances the operation and returns what it needs next. Never blocks.

§Errors
§Examples

See FileWriterCore.

Source

pub fn output_src(&self) -> &[u8] ⓘ

The bytes to write now: one stretch of one segment, never a concatenation (§ 3).

For a payload this is a slice of the caller’s own memory; for padding it is a window onto a shared page of zeroes, so the same bytes may be offered repeatedly until the padding is out.

§Examples

See FileWriterCore.

Source

pub fn report_written(&mut self, n: usize) -> Result<()>

Reports that the sink accepted n bytes of output_src.

A short write re-offers the remainder.

§Errors
§Examples

See FileWriterCore.

Source

pub fn emitted(&self) -> u64

Bytes of this item already accepted by the sink, padding included.

Zero means nothing of the item has left the driver, which is exactly when the item may be resubmitted after a failure (§ 6b).

§Examples
use hurray_io::file::FileWriterCore;

let mut core = FileWriterCore::new();
let mut op = core.header()?;
// Stepping offers bytes; only a report counts them.
op.step()?;
assert_eq!(op.emitted(), 0);

op.report_written(16)?;
assert_eq!(op.emitted(), 16);
Source

pub fn report_sink_closed(&mut self) -> Error

Declares the sink closed while this item is in flight.

Returns the error to propagate. A partially written file has a torn item in it and no footer, so this poisons the core: a fresh operation on the same sink is not a recovery (§ 6).

§Examples
let mut op = core.header()?;
let error = op.report_sink_closed();
assert!(matches!(error, hurray_io::Error::SinkClosed));

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for FileWriteOp<'a>

§

impl<'a> Freeze for FileWriteOp<'a>

§

impl<'a> RefUnwindSafe for FileWriteOp<'a>

§

impl<'a> Send for FileWriteOp<'a>

§

impl<'a> Sync for FileWriteOp<'a>

§

impl<'a> Unpin for FileWriteOp<'a>

§

impl<'a> UnsafeUnpin for FileWriteOp<'a>

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