Struct buf_redux::BufWriter
[−]
[src]
pub struct BufWriter<W: Write, Fs: FlushStrategy = DefaultFlushStrategy> { /* fields omitted */ }
A drop-in replacement for std::io::BufWriter
with more control over the buffer size and the flushing
strategy.
Methods
impl<W: Write> BufWriter<W, DefaultFlushStrategy>
[src]
fn new(inner: W) -> Self
Wrap inner
with the default buffer capacity and flush strategy.
fn with_capacity(capacity: usize, inner: W) -> Self
Wrap inner
with the given buffer capacity and the default flush strategy.
impl<W: Write, Fs: FlushStrategy> BufWriter<W, Fs>
[src]
fn with_strategy(inner: W, flush_strat: Fs) -> Self
Wrap inner
with the default buffer capacity and given flush strategy
fn with_capacity_and_strategy(capacity: usize,
inner: W,
flush_strat: Fs)
-> Self
inner: W,
flush_strat: Fs)
-> Self
Wrap inner
with the given buffer capacity and flush strategy.
fn flush_strategy<Fs_: FlushStrategy>(self,
flush_strat: Fs_)
-> BufWriter<W, Fs_>
flush_strat: Fs_)
-> BufWriter<W, Fs_>
Set a new FlushStrategy
, returning the transformed type.
fn flush_strategy_mut(&mut self) -> &mut Fs
Mutate the current flush strategy.
fn get_ref(&self) -> &W
Get a reference to the inner writer.
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.
fn capacity(&self) -> usize
Get the capacty of the inner buffer.
fn buffered(&self) -> usize
Get the number of bytes currently in the buffer.
fn grow(&mut self, additional: usize)
Grow the internal buffer by at least additional
bytes. May not be
quite exact due to implementation details of the buffer's allocator.
Note
This should not be called frequently as each call will incur a reallocation.
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.
fn into_inner_with_err(self) -> (W, Option<Error>)
Flush the buffer and unwrap, returning the inner writer and any error encountered during flushing.
fn into_inner_with_buf(self) -> (W, Vec<u8>)
Consume self
and return both the underlying writer and the buffer,
with the data moved to the beginning and the length truncated to contain
only valid data.
Trait Implementations
impl<W: Write, Fs: FlushStrategy> Write for BufWriter<W, Fs>
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this object, returning how many bytes were written. Read more
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0
Attempts to write an entire buffer into this write. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0
Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0
Creates a "by reference" adaptor for this instance of Write
. Read more
impl<W: Write + Seek, Fs: FlushStrategy> Seek for BufWriter<W, Fs>
[src]
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.