Trait rmpv::decode::value_ref::BorrowRead

source ·
pub trait BorrowRead<'a>: Read {
    // Required methods
    fn fill_buf(&self) -> &'a [u8] ;
    fn consume(&mut self, len: usize);
}
Expand description

A BorrowRead is a type of Reader which has an internal buffer.

This magic trait acts like a standard BufRead but unlike the standard this has an explicit internal buffer lifetime, which allows to borrow from underlying buffer while consuming bytes.

Required Methods§

source

fn fill_buf(&self) -> &'a [u8]

Returns the buffer contents.

This function is a lower-level call. It needs to be paired with the consume method to function properly. When calling this method, none of the contents will be “read” in the sense that later calling read may return the same contents. As such, consume must be called with the number of bytes that are consumed from this buffer to ensure that the bytes are never returned twice.

An empty buffer returned indicates that the stream has reached EOF.

source

fn consume(&mut self, len: usize)

Tells this buffer that len bytes have been consumed from the buffer, so they should no longer be returned in calls to read.

Implementations on Foreign Types§

source§

impl<'a> BorrowRead<'a> for &'a [u8]

source§

fn fill_buf(&self) -> &'a [u8]

source§

fn consume(&mut self, len: usize)

source§

impl<'a> BorrowRead<'a> for Cursor<&'a [u8]>

Useful when you want to know how much bytes has been consumed during ValueRef decoding.

source§

fn fill_buf(&self) -> &'a [u8]

source§

fn consume(&mut self, len: usize)

Implementors§