Trait lexical_util::buffer::Buffer

source ·
pub unsafe trait Buffer<'a> {
    const IS_CONTIGUOUS: bool;

    // Required methods
    fn as_ptr(&self) -> *const u8;
    fn as_slice(&self) -> &'a [u8] ;
    unsafe fn first_unchecked(&self) -> &'a u8;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn is_contiguous(&self) -> bool { ... }
    fn first(&self) -> Option<&'a u8> { ... }
    fn first_is(&self, value: u8) -> bool { ... }
    fn case_insensitive_first_is(&self, value: u8) -> bool { ... }
}
Expand description

A trait for working with iterables of bytes.

These buffers can either be contiguous or not contiguous and provide methods for reading data and accessing underlying data. The readers can either be contiguous or non-contiguous, although performance and some API methods may not be available for both.

§Safety

This trait is effectively safe but the implementor must guarantee that is_empty is implemented correctly. For most implementations, this can be self.as_slice().is_empty(), where as_slice is implemented as &self.bytes[self.index..].

Required Associated Constants§

source

const IS_CONTIGUOUS: bool

Determine if the buffer is contiguous in memory.

Required Methods§

source

fn as_ptr(&self) -> *const u8

Get a ptr to the current start of the buffer.

source

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

Get a slice to the current start of the buffer.

source

unsafe fn first_unchecked(&self) -> &'a u8

Peek the next value of the buffer, without checking bounds.

§Safety

Safe as long as there is at least a single valid value left in the buffer. Note that the behavior of this may lead to out-of-bounds access (for contiguous buffers) or panics (for non-contiguous buffers).

Provided Methods§

source

fn is_empty(&self) -> bool

Get if no bytes are available in the buffer.

This operators on the underlying buffer: that is, it returns if as_slice would return an empty slice.

source

fn is_contiguous(&self) -> bool

Determine if the buffer is contiguous.

source

fn first(&self) -> Option<&'a u8>

Get the next value available without consuming it.

§Safety

An implementor must implement is_empty correctly in order to guarantee the traitt is safe: is_empty MUST ensure that one value remains, if the iterator is non- contiguous this means advancing the iterator to the next position.

source

fn first_is(&self, value: u8) -> bool

Check if the next element is a given value.

source

fn case_insensitive_first_is(&self, value: u8) -> bool

Check if the next element is a given value without case sensitivity.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'a, const FORMAT: u128> Buffer<'a> for Bytes<'a, FORMAT>