Skip to main content

WriteOut

Struct WriteOut 

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

Source

pub fn new(writer: W) -> Self

Source

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.

Source

pub fn with_limits(self, limits: &Limits) -> Self

Enforce limits.max_output_bytes; the other limits belong to the stages upstream.

Source

pub fn with_metrics(self, metrics: Arc<Metrics>) -> Self

Count output_bytes into these metrics.

Source

pub fn accepted(&self) -> u64

Bytes accepted so far, buffered or written.

Source

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.

Source

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>

Source§

fn write_str(&mut self, s: &str) -> Result<(), Fail>

Source§

fn flush(&mut self) -> Result<(), Fail>

Source§

fn has_committed(&self) -> bool

Whether any text has reached the final destination, so that a failure found now leaves partial output behind. A renderer asks this when it fails and reports 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.

Auto Trait Implementations§

§

impl<W> Freeze for WriteOut<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for WriteOut<W>
where W: RefUnwindSafe,

§

impl<W> Send for WriteOut<W>
where W: Send,

§

impl<W> Sync for WriteOut<W>
where W: Sync,

§

impl<W> Unpin for WriteOut<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for WriteOut<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for WriteOut<W>
where W: UnwindSafe,

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.