Struct std::io::buffered::linewritershim::LineWriterShim[][src]

pub struct LineWriterShim<'a, W: Write> {
    buffer: &'a mut BufWriter<W>,
}
Expand description

Private helper struct for implementing the line-buffered writing logic. This shim temporarily wraps a BufWriter, and uses its internals to implement a line-buffered writer (specifically by using the internal methods like write_to_buf and flush_buf). In this way, a more efficient abstraction can be created than one that only had access to write and flush, without needlessly duplicating a lot of the implementation details of BufWriter. This also allows existing BufWriters to be temporarily given line-buffering logic; this is what enables Stdout to be alternately in line-buffered or block-buffered mode.

Fields

buffer: &'a mut BufWriter<W>

Implementations

Get a reference to the inner writer (that is, the writer wrapped by the BufWriter).

Get a mutable reference to the inner writer (that is, the writer wrapped by the BufWriter). Be careful with this writer, as writes to it will bypass the buffer.

Get the content currently buffered in self.buffer

Flush the buffer iff the last byte is a newline (indicating that an earlier write only succeeded partially, and we want to retry flushing the buffered line before continuing with a subsequent write)

Trait Implementations

Formats the value using the given formatter. Read more

Write some data into this BufReader with line buffering. This means that, if any newlines are present in the data, the data up to the last newline is sent directly to the underlying writer, and data after it is buffered. Returns the number of bytes written.

This function operates on a “best effort basis”; in keeping with the convention of Write::write, it makes at most one attempt to write new data to the underlying writer. If that write only reports a partial success, the remaining data will be buffered.

Because this function attempts to send completed lines to the underlying writer, it will also flush the existing buffer if it ends with a newline, even if the incoming data does not contain any newlines.

Write some vectored data into this BufReader with line buffering. This means that, if any newlines are present in the data, the data up to and including the buffer containing the last newline is sent directly to the inner writer, and the data after it is buffered. Returns the number of bytes written.

This function operates on a “best effort basis”; in keeping with the convention of Write::write, it makes at most one attempt to write new data to the underlying writer.

Because this function attempts to send completed lines to the underlying writer, it will also flush the existing buffer if it contains any newlines.

Because sorting through an array of IoSlice can be a bit convoluted, This method differs from write in the following ways:

  • It attempts to write the full content of all the buffers up to and including the one containing the last newline. This means that it may attempt to write a partial line, that buffer has data past the newline.
  • If the write only reports partial success, it does not attempt to find the precise location of the written bytes and buffer the rest.

If the underlying vector doesn’t support vectored writing, we instead simply write the first non-empty buffer with write. This way, we get the benefits of more granular partial-line handling without losing anything in efficiency

Write some data into this BufReader with line buffering. This means that, if any newlines are present in the data, the data up to the last newline is sent directly to the underlying writer, and data after it is buffered.

Because this function attempts to send completed lines to the underlying writer, it will also flush the existing buffer if it contains any newlines, even if the incoming data does not contain any newlines.

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

🔬 This is a nightly-only experimental API. (can_vector #69941)

Determines if this Writer has an efficient write_vectored implementation. Read more

🔬 This is a nightly-only experimental API. (write_all_vectored #70436)

Attempts to write multiple buffers into this writer. Read more

Writes a formatted string into this writer, returning any error encountered. Read more

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.