[][src]Trait buf_redux::policy::WriterPolicy

pub trait WriterPolicy {
    fn before_write(&mut self, buf: &mut Buffer, incoming: usize) -> FlushAmt { ... }
fn after_write(&mut self, _buf: &Buffer) -> FlushAmt { ... } }

A trait which tells BufWriter when to flush.

Provided methods

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.

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.

Loading content...

Implementors

impl WriterPolicy for FlushAtLeast[src]

impl WriterPolicy for FlushExact[src]

fn before_write(&mut self, buf: &mut Buffer, incoming: usize) -> FlushAmt[src]

Flushes the buffer if there is not enough room to fit incoming bytes, but only when the buffer contains at least self.0 bytes.

Otherwise, calls Buffer::make_room()

fn after_write(&mut self, _buf: &Buffer) -> FlushAmt[src]

Flushes the given amount if possible, nothing otherwise.

impl WriterPolicy for FlushOn[src]

impl WriterPolicy for FlushOnNewline[src]

impl WriterPolicy for StdPolicy[src]

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.

Loading content...