pub trait WriterPolicy {
// Provided methods
fn before_write(&mut self, buf: &mut Buffer, incoming: usize) -> FlushAmt { ... }
fn after_write(&mut self, _buf: &Buffer) -> FlushAmt { ... }
}
Expand description
A trait which tells BufWriter
when to flush.
Provided Methods§
Sourcefn before_write(&mut self, buf: &mut Buffer, incoming: usize) -> FlushAmt
fn before_write(&mut self, buf: &mut Buffer, incoming: usize) -> FlushAmt
Return FlushAmt(n > 0)
if the buffer should be flushed before reading into it.
If the returned amount is 0 or greater than the amount of buffered data, no flush is
performed.
The buffer is provided, as well as incoming
which is
the size of the buffer that will be written to the BufWriter
.
By default, flushes the buffer if the usable space is smaller than the incoming write.
Sourcefn after_write(&mut self, _buf: &Buffer) -> FlushAmt
fn after_write(&mut self, _buf: &Buffer) -> FlushAmt
Return true
if the buffer should be flushed after reading into it.
buf
references the updated buffer after the read.
Default impl is a no-op.
Implementors§
impl WriterPolicy for FlushAtLeast
impl WriterPolicy for FlushExact
impl WriterPolicy for FlushOn
impl WriterPolicy for FlushOnNewline
impl WriterPolicy for StdPolicy
Default behavior of std::io::BufWriter
: flush before a read into the buffer
only if the incoming data is larger than the buffer’s writable space.