pub trait UnderlyingBuffer: Index<Range<usize>, Output = [u8]> + Index<usize, Output = u8> {
    // Required methods
    fn clear(&mut self);
    fn len(&self) -> usize;
    fn max_capacity(&self) -> usize;
    fn extend_from_slice(&mut self, other: &[u8]) -> usize;
    fn drain(&mut self, count: usize);

    // Provided methods
    fn find(&self, value: u8) -> Option<usize> { ... }
    fn is_empty(&self) -> bool { ... }
}
Expand description

This trait represents an underlying buffer used for the Parser. We provide implementations for Vec<u8> and for FixedLinearBuffer, if you want to use your own struct as an underlying buffer you can implement this trait.

Look at the flb_* unit tests for ideas of unit tests you can run against your own implementations.

Required Methods§

source

fn clear(&mut self)

Removes all elements from the buffer.

source

fn len(&self) -> usize

Returns the number of elements currently stored in the buffer.

source

fn max_capacity(&self) -> usize

Returns the maximum capacity of this buffer. This value should be a minimum max capacity - that is, extend_from_slice should succeed if max_capacity bytes are passed to it.

Note that, for example, the Vec implementation of this trait returns usize::MAX, which cannot be actually allocated by a Vec. This is okay, because Vec will panic if an allocation is requested that it can’t handle.

source

fn extend_from_slice(&mut self, other: &[u8]) -> usize

Returns the number of bytes not copied over due to buffer size constraints.

As noted for max_capacity, if this function is passed max_capacity() - len() bytes it should either panic or return zero bytes, any other behaviour may cause unexpected behaviour in the parser.

source

fn drain(&mut self, count: usize)

Removes the first count elements from the buffer. Cannot fail.

Provided Methods§

source

fn find(&self, value: u8) -> Option<usize>

Locates the given u8 value within the buffer, returning the index (if it is found).

source

fn is_empty(&self) -> bool

Returns whether the buffer is empty.

Implementations on Foreign Types§

source§

impl UnderlyingBuffer for Vec<u8>

source§

fn clear(&mut self)

source§

fn len(&self) -> usize

source§

fn max_capacity(&self) -> usize

source§

fn extend_from_slice(&mut self, other: &[u8]) -> usize

source§

fn drain(&mut self, count: usize)

source§

fn find(&self, value: u8) -> Option<usize>

Implementors§