Trait ublox::UnderlyingBuffer
source · 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§
sourcefn max_capacity(&self) -> usize
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.
sourcefn extend_from_slice(&mut self, other: &[u8]) -> usize
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.