Skip to main content

BufWriter

Struct BufWriter 

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

Wraps a writer and buffers its output.

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

Implementations§

Source§

impl<W: Write> BufWriter<W>

Source

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

Creates a new BufWriter<W> with a default buffer capacity.

Source

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

Unwraps this BufWriter<W>, returning the underlying writer.

The buffer is written out before returning the writer.

§Errors

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

Source

pub fn into_parts( self, ) -> (W, Result<Vec<u8, DEFAULT_BUF_SIZE, u16>, WriterPanicked>)

Disassembles this BufWriter<W>, returning the underlying writer, and any buffered but unwritten data.

If the underlying writer panicked, it is not known what portion of the data was written. In this case, we return WriterPanicked for the buffered data (from which the buffer contents can still be recovered).

into_parts makes no attempt to flush data and cannot fail.

Source§

impl<W: ?Sized + Write> BufWriter<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.

It is inadvisable to directly write to the underlying writer.

Source

pub fn buffer(&self) -> &[u8]

Returns a reference to the internally buffered data.

Source

pub fn capacity(&self) -> usize

Returns the number of bytes the internal buffer can hold without flushing.

Trait Implementations§

Source§

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

Source§

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

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

impl<W: ?Sized + Write> Drop for BufWriter<W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<W: ?Sized + Write + IoBufMut> IoBufMut for BufWriter<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 + Seek> Seek for BufWriter<W>

Source§

fn seek(&mut self, pos: SeekFrom) -> Result<u64>

Seek to the offset, in bytes, in the underlying writer.

Seeking always writes out the internal buffer before seeking.

Source§

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

Rewind to the beginning of a stream. Read more
Source§

fn stream_position(&mut self) -> Result<u64>

Returns the current seek position from the start of the stream. Read more
Source§

fn stream_len(&mut self) -> Result<u64>

Returns the length of this stream (in bytes).
Source§

fn seek_relative(&mut self, offset: i64) -> Result<()>

Seeks relative to the current position.
Source§

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

Source§

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

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

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

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

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

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

fn write_fmt(&mut self, args: 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 BufWriter<W>
where W: Freeze + ?Sized,

§

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

§

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

§

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

§

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

§

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

§

impl<W> UnwindSafe for BufWriter<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.