Trait buffer_redux::policy::WriterPolicy

source ·
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§

source

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.

source

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§

source§

impl WriterPolicy for FlushAtLeast

source§

impl WriterPolicy for FlushExact

source§

impl WriterPolicy for FlushOn

source§

impl WriterPolicy for FlushOnNewline

source§

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.