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§
sourceconst IS_CONTIGUOUS: bool
const IS_CONTIGUOUS: bool
Determine if each yielded value is adjacent in memory.
Required Methods§
sourceunsafe fn set_cursor(&mut self, index: usize)
unsafe fn set_cursor(&mut self, index: usize)
sourcefn current_count(&self) -> usize
fn current_count(&self) -> usize
Get the current number of values returned by the iterator.
sourcefn is_consumed(&mut self) -> bool
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.
sourcefn is_done(&self) -> bool
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()
.
sourceunsafe fn peek_unchecked(&mut self) -> Self::Item
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).
sourcefn peek(&mut self) -> Option<Self::Item>
fn peek(&mut self) -> Option<Self::Item>
Peek the next value of the iterator, without consuming it.
sourceunsafe fn read_unchecked<V>(&self) -> V
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.
sourcefn read<V>(&self) -> Option<V>
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.
sourceunsafe fn step_by_unchecked(&mut self, count: usize)
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§
sourcefn is_contiguous(&self) -> bool
fn is_contiguous(&self) -> bool
Determine if the iterator is contiguous.
sourcefn case_insensitive_peek_is(&mut self, value: u8) -> bool
fn case_insensitive_peek_is(&mut self, value: u8) -> bool
Check if the next element is a given value without case sensitivity.
sourcefn skip_zeros(&mut self) -> usize
fn skip_zeros(&mut self) -> usize
Skip zeros from the start of the iterator