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<'_>
impl FileWriteOp<'_>
Sourcepub fn step(&mut self) -> Result<WriteStep>
pub fn step(&mut self) -> Result<WriteStep>
Advances the operation and returns what it needs next. Never blocks.
§Errors
Error::CoreFailed— a previous call ended this operationError::CoreUnusable— the core was poisoned mid-item
§Examples
See FileWriterCore.
Sourcepub fn output_src(&self) -> &[u8] ⓘ
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.
Sourcepub fn report_written(&mut self, n: usize) -> Result<()>
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
Error::ZeroLengthWrite—n == 0, which § 4 forbids treating as progress. A sink that cannot accept bytes is reported withreport_sink_closedinstead.Error::InvalidProgressReport— more bytes reported than were offered. An unknown number of bytes is then on the sink and cannot be un-written, so this poisons the core (§ 6).
§Examples
See FileWriterCore.
Sourcepub fn emitted(&self) -> u64
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);Sourcepub fn report_sink_closed(&mut self) -> Error
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));