Skip to main content

LineWriter

Struct LineWriter 

Source
pub struct LineWriter<W: ?Sized + Write> { /* private fields */ }
Expand description

The BufWriter struct wraps a writer and buffers its output. But it only does this batched write when it goes out of scope, or when the internal buffer is full. Sometimes, you’d prefer to write each line as it’s completed, rather than the entire buffer at once. Enter LineWriter. It does exactly that.

Like BufWriter, a LineWriter’s buffer will also be flushed when the LineWriter goes out of scope or when its internal buffer is full.

If there’s still a partial line in the buffer when the LineWriter is dropped, it will flush those contents.

See std::io::LineWriter for more details.

Implementations§

Source§

impl<W: Write> LineWriter<W>

Source

pub fn new(inner: W) -> LineWriter<W>

Creates a new LineWriter.

Source

pub fn into_inner(self) -> Result<W, IntoInnerError<LineWriter<W>>>

Unwraps this LineWriter, returning the underlying writer.

The internal buffer is written out before returning the writer.

§Errors

An Err will be returned if an error occurs while flushing the buffer.

Source§

impl<W: ?Sized + Write> LineWriter<W>

Source

pub fn get_ref(&self) -> &W

Gets a reference to the underlying writer.

Source

pub fn get_mut(&mut self) -> &mut W

Gets a mutable reference to the underlying writer.

Caution must be taken when calling methods on the mutable reference returned as extra writes could corrupt the output stream.

Trait Implementations§

Source§

impl<W: ?Sized + Write + Debug> Debug for LineWriter<W>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<W: ?Sized + Write + IoBufMut> IoBufMut for LineWriter<W>

Source§

fn remaining_mut(&self) -> usize

Returns the number of bytes that can be written from the current position until the end of the buffer is reached.
Source§

fn is_full(&self) -> bool

Returns true if there is no remaining space in the buffer.
Source§

impl<W: ?Sized + Write> Write for LineWriter<W>

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Write a buffer into this writer, returning how many bytes were written.
Source§

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

Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
Source§

fn write_all(&mut self, buf: &[u8]) -> Result<()>

Attempts to write an entire buffer into this writer.
Source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>

Writes a formatted string into this writer, returning any error encountered.
Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

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

Auto Trait Implementations§

§

impl<W> Freeze for LineWriter<W>
where W: Freeze + ?Sized,

§

impl<W> RefUnwindSafe for LineWriter<W>
where W: RefUnwindSafe + ?Sized,

§

impl<W> Send for LineWriter<W>
where W: Send + ?Sized,

§

impl<W> Sync for LineWriter<W>
where W: Sync + ?Sized,

§

impl<W> Unpin for LineWriter<W>
where W: Unpin + ?Sized,

§

impl<W> UnsafeUnpin for LineWriter<W>
where W: UnsafeUnpin + ?Sized,

§

impl<W> UnwindSafe for LineWriter<W>
where W: UnwindSafe + ?Sized,

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> IoBufMutExt for T
where T: Write + IoBufMut + ?Sized,

Source§

fn read_from<R: Read + ?Sized>(&mut self, reader: &mut R) -> Result<usize>

Reads some bytes from reader and writes them into this buffer.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.