Trait lexical_util::iterator::BytesIter

source ·
pub trait BytesIter<'a>: Iterator<Item = &'a u8> {
    const IS_CONTIGUOUS: bool;
Show 18 methods // Required methods fn as_ptr(&self) -> *const u8; fn as_slice(&self) -> &'a [u8]; fn length(&self) -> usize; fn cursor(&self) -> usize; unsafe fn set_cursor(&mut self, index: usize); fn current_count(&self) -> usize; fn is_consumed(&mut self) -> bool; fn is_done(&self) -> bool; unsafe fn peek_unchecked(&mut self) -> Self::Item; fn peek(&mut self) -> Option<Self::Item>; unsafe fn read_unchecked<V>(&self) -> V; fn read<V>(&self) -> Option<V>; unsafe fn step_by_unchecked(&mut self, count: usize); // Provided methods fn is_contiguous(&self) -> bool { ... } fn peek_is(&mut self, value: u8) -> bool { ... } fn case_insensitive_peek_is(&mut self, value: u8) -> bool { ... } fn skip_zeros(&mut self) -> usize { ... } unsafe fn step_unchecked(&mut self) { ... }
}
Expand description

Iterator over a contiguous block of bytes.

This allows us to convert to-and-from-slices, raw pointers, and peek/query the data from either end cheaply.

A default implementation is provided for slice iterators. This trait should never return null from as_ptr, or be implemented for non-contiguous data.

Required Associated Constants§

source

const IS_CONTIGUOUS: bool

Determine if each yielded value is adjacent in memory.

Required Methods§

source

fn as_ptr(&self) -> *const u8

Get a ptr to the current start of the iterator.

source

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

Get a slice to the current start of the iterator.

source

fn length(&self) -> usize

Get the total number of elements in the underlying slice.

source

fn cursor(&self) -> usize

Get the current index of the iterator in the slice.

source

unsafe fn set_cursor(&mut self, index: usize)

Set the current index of the iterator in the slice.

§Safety

Safe if index <= self.length().

source

fn current_count(&self) -> usize

Get the current number of values returned by the iterator.

source

fn is_consumed(&mut self) -> bool

Get if the iterator cannot return any more elements.

This may advance the internal iterator state, but not modify the next returned value.

source

fn is_done(&self) -> bool

Get if the buffer underlying the iterator is empty.

This might not be the same thing as is_consumed: is_consumed checks if any more elements may be returned, which may require peeking the next value. Consumed merely checks if the iterator has an empty slice. It is effectively a cheaper, but weaker variant of is_consumed().

source

unsafe fn peek_unchecked(&mut self) -> Self::Item

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

§Safety

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

source

fn peek(&mut self) -> Option<Self::Item>

Peek the next value of the iterator, without consuming it.

source

unsafe fn read_unchecked<V>(&self) -> V

Read a value of a difference type from the iterator. This advances the internal state of the iterator.

§Safety

Safe as long as the number of the buffer is contains as least as many bytes as the size of V.

source

fn read<V>(&self) -> Option<V>

Try to read a value of a different type from the iterator. This advances the internal state of the iterator.

source

unsafe fn step_by_unchecked(&mut self, count: usize)

Advance the internal slice by N elements.

§Safety

As long as the iterator is at least N elements, this is safe.

Provided Methods§

source

fn is_contiguous(&self) -> bool

Determine if the iterator is contiguous.

source

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

Check if the next element is a given value.

source

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

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

source

fn skip_zeros(&mut self) -> usize

Skip zeros from the start of the iterator

source

unsafe fn step_unchecked(&mut self)

Advance the internal slice by 1 element.

§Safety

Safe as long as the iterator is not empty.

Object Safety§

This trait is not object safe.

Implementors§