pub struct LineWriter<W: Write>(/* private fields */);
Expand description
A drop-in replacement for std::io::LineWriter
with more functionality.
This is, in fact, only a thin wrapper around
BufWriter
<W,
policy::FlushOnNewline
>
, which
demonstrates the power of custom WriterPolicy
implementations.
Implementations§
Source§impl<W: Write> LineWriter<W>
impl<W: Write> LineWriter<W>
Sourcepub fn with_capacity(cap: usize, inner: W) -> Self
pub fn with_capacity(cap: usize, inner: W) -> Self
Wrap inner
with the given buffer capacity.
Sourcepub fn with_buffer(buf: Buffer, inner: W) -> LineWriter<W> ⓘ
pub fn with_buffer(buf: Buffer, inner: W) -> LineWriter<W> ⓘ
Wrap inner
with an existing Buffer
instance.
§Note
Does not clear the buffer first! If there is data already in the buffer it will be written out on the next flush!
Sourcepub fn get_mut(&mut self) -> &mut W
pub fn get_mut(&mut self) -> &mut W
Get a mutable reference to the inner writer.
§Note
If the buffer has not been flushed, writing directly to the inner type will cause data inconsistency.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Ensure enough space in the buffer for at least additional
bytes. May not be
quite exact due to implementation details of the buffer’s allocator.
Sourcepub fn into_inner(self) -> Result<W, IntoInnerError<Self>>
pub fn into_inner(self) -> Result<W, IntoInnerError<Self>>
Flush the buffer and unwrap, returning the inner writer on success,
or a type wrapping self
plus the error otherwise.
Sourcepub fn into_inner_with_err(self) -> (W, Option<Error>)
pub fn into_inner_with_err(self) -> (W, Option<Error>)
Flush the buffer and unwrap, returning the inner writer and any error encountered during flushing.
Sourcepub fn into_inner_with_buf(self) -> (W, Buffer)
pub fn into_inner_with_buf(self) -> (W, Buffer)
Consume self
and return both the underlying writer and the buffer.
Trait Implementations§
Source§impl<W: Write> Write for LineWriter<W>
impl<W: Write> Write for LineWriter<W>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)