pub trait ReaderPolicy {
// Provided methods
fn before_read(&mut self, buffer: &mut Buffer) -> DoRead { ... }
fn after_consume(&mut self, _buffer: &mut Buffer, _amt: usize) { ... }
}
Expand description
Trait that governs BufReader
’s behavior.
Provided Methods§
Sourcefn before_read(&mut self, buffer: &mut Buffer) -> DoRead
fn before_read(&mut self, buffer: &mut Buffer) -> DoRead
Consulted before attempting to read into the buffer.
Return DoRead(true)
to issue a read into the buffer before reading data out of it,
or DoRead(false)
to read from the buffer as it is, even if it’s empty.
do_read!()
is provided as a shorthand.
If there is no room in the buffer after this method is called,
the buffer will not be read into (so if the buffer is full but you want more data
you should call .make_room()
or reserve more space). If there is room, BufReader
will
attempt to read into the buffer. If successful (Ok(x)
where x > 0
is returned), this
method will be consulted again for another read attempt.
By default, this implements std::io::BufReader
’s behavior: only read into the buffer if
it is empty.
§Note
If the read will ignore the buffer entirely (if the buffer is empty and the amount to be
read matches or exceeds its capacity) or if BufReader::read_into_buf()
was called to force
a read into the buffer manually, this method will not be called.
Sourcefn after_consume(&mut self, _buffer: &mut Buffer, _amt: usize)
fn after_consume(&mut self, _buffer: &mut Buffer, _amt: usize)
Called after bytes are consumed from the buffer.
Supplies the true amount consumed if the amount passed to BufReader::consume
was in excess.
This is a no-op by default.
Implementors§
impl ReaderPolicy for MinBuffered
impl ReaderPolicy for StdPolicy
Behavior of std::io::BufReader
: the buffer will only be read into if it is empty.