pub struct WriteOut<W: Write> { /* private fields */ }Expand description
Coalesces fragments and writes them to an io::Write.
Retention is bounded by the budget: the buffer never holds more than
budget bytes, and a fragment at least as large as the budget goes to
the writer directly, after whatever was buffered before it. The output
limit is checked on every fragment BEFORE it is accepted, counting the
bytes buffered as well as the bytes written, so a run that would exceed
max_output_bytes fails without emitting the fragment that crossed the
line. output_bytes in the shared Metrics counts bytes the writer
accepted, which is what “written to the output” means to a caller
reading the metrics after a failure; like committed(), it is kept
per write call, so the part of a buffer a writer took before failing
is counted.
Implementations§
Source§impl<W: Write> WriteOut<W>
impl<W: Write> WriteOut<W>
pub fn new(writer: W) -> Self
Sourcepub fn with_budget(self, budget: usize) -> Self
pub fn with_budget(self, budget: usize) -> Self
The coalescing budget in bytes. Zero means every fragment is written as it arrives, which is what a test of the writer’s ordering wants.
Sourcepub fn with_limits(self, limits: &Limits) -> Self
pub fn with_limits(self, limits: &Limits) -> Self
Enforce limits.max_output_bytes; the other limits belong to the
stages upstream.
Sourcepub fn with_metrics(self, metrics: Arc<Metrics>) -> Self
pub fn with_metrics(self, metrics: Arc<Metrics>) -> Self
Count output_bytes into these metrics.
Sourcepub fn committed(&self) -> u64
pub fn committed(&self) -> u64
Bytes the writer accepted, including the bytes of a short write
that a failure cut off: after OUTPUT_FAILED this is what the
writer holds, not the buffers that were sent whole.
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Hand the writer back WITHOUT flushing. Whatever the buffer still
holds is dropped, so the writer holds exactly the bytes committed()
counts, a short write before a failure included: a document that
failed before its End does not reach the writer on the way out,
which is what a failure that reported no committed output promised
the host. A renderer flushes once, at its End, and a caller that
wants a partial output anyway calls flush first, knowingly.
Trait Implementations§
Source§impl<W: Write> TextOut for WriteOut<W>
impl<W: Write> TextOut for WriteOut<W>
fn write_str(&mut self, s: &str) -> Result<(), Fail>
fn flush(&mut self) -> Result<(), Fail>
Source§fn has_committed(&self) -> bool
fn has_committed(&self) -> bool
committed_output from the answer, which
is how a host knows to print output: "partial" rather than
"none". The default is the conservative answer for an output that
cannot tell: whatever the renderer handed over may be out.
WriteOut answers exactly, from the bytes its writer received; a
fragment that is still buffered is not committed, and into_inner
drops it rather than sending it after the fact.