Trait lexical_util::iterator::Iter
source · pub trait Iter<'a> {
const IS_CONTIGUOUS: bool;
Show 18 methods
// Required methods
fn get_buffer(&self) -> &'a [u8] ⓘ;
fn cursor(&self) -> usize;
unsafe fn set_cursor(&mut self, index: usize);
fn current_count(&self) -> usize;
unsafe fn step_by_unchecked(&mut self, count: usize);
// Provided methods
fn as_ptr(&self) -> *const u8 { ... }
fn as_slice(&self) -> &'a [u8] ⓘ { ... }
fn buffer_length(&self) -> usize { ... }
fn is_buffer_empty(&self) -> bool { ... }
fn is_contiguous(&self) -> bool { ... }
fn first(&self) -> Option<&'a u8> { ... }
fn first_is_cased(&self, value: u8) -> bool { ... }
fn first_is_uncased(&self, value: u8) -> bool { ... }
fn first_is(&mut self, value: u8, is_cased: bool) -> bool { ... }
unsafe fn step_unchecked(&mut self) { ... }
unsafe fn peek_many_unchecked<V>(&self) -> V { ... }
fn peek_u32(&self) -> Option<u32> { ... }
fn peek_u64(&self) -> Option<u64> { ... }
}
Expand description
A trait for working with iterables of bytes.
These iterators 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.
Required Associated Constants§
sourceconst IS_CONTIGUOUS: bool
const IS_CONTIGUOUS: bool
Determine if the buffer is contiguous in memory.
Required Methods§
sourcefn get_buffer(&self) -> &'a [u8] ⓘ
fn get_buffer(&self) -> &'a [u8] ⓘ
Get a slice to the full underlying contiguous buffer,
sourceunsafe fn set_cursor(&mut self, index: usize)
unsafe fn set_cursor(&mut self, index: usize)
Set the current index of the iterator in the slice.
This is NOT the current position of the iterator,
since iterators may skip digits: this is the cursor
in the underlying buffer. For example, if slc[2]
is
skipped, set_cursor(3)
would be the 3rd element in
the iterator, not the 4th.
§Safety
Safe if index <= self.buffer_length()
. Although this
won’t affect safety, the caller also should be careful it
does not set the cursor within skipped characters
since this could affect correctness: an iterator that
only accepts non-consecutive digit separators would
pass if the cursor was set between the two.
sourcefn current_count(&self) -> usize
fn current_count(&self) -> usize
Get the current number of values returned by the iterator.
For contiguous iterators, this is always the cursor, for non-contiguous iterators this can be smaller.
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.
This does not advance the iterator by N
elements for
non-contiguous iterators: this just advances the internal,
underlying buffer. This is useful for multi-digit optimizations
for contiguous iterators.
§Panics
This will panic if the buffer advances for non-contiguous iterators if the current byte is a digit separator, or if the count is more than 1.
§Safety
As long as the iterator is at least N
elements, this
is safe.
Provided Methods§
sourcefn buffer_length(&self) -> usize
fn buffer_length(&self) -> usize
Get the total number of elements in the underlying buffer.
sourcefn is_buffer_empty(&self) -> bool
fn is_buffer_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.
sourcefn is_contiguous(&self) -> bool
fn is_contiguous(&self) -> bool
Determine if the buffer is contiguous.
sourcefn first(&self) -> Option<&'a u8>
fn first(&self) -> Option<&'a u8>
Get the next value available without consuming it.
This does NOT skip digits, and directly fetches the item from the underlying buffer.
sourcefn first_is_cased(&self, value: u8) -> bool
fn first_is_cased(&self, value: u8) -> bool
Check if the next element is a given value.
sourcefn first_is_uncased(&self, value: u8) -> bool
fn first_is_uncased(&self, value: u8) -> bool
Check if the next element is a given value without case sensitivity.
sourcefn first_is(&mut self, value: u8, is_cased: bool) -> bool
fn first_is(&mut self, value: u8, is_cased: bool) -> bool
Check if the next item in buffer is a given value with optional case sensitivity.
sourceunsafe fn step_unchecked(&mut self)
unsafe fn step_unchecked(&mut self)
sourceunsafe fn peek_many_unchecked<V>(&self) -> V
unsafe fn peek_many_unchecked<V>(&self) -> V
Read a value of a difference type from the iterator.
This does not advance the internal state of the iterator. This can only be implemented for contiguous iterators: non- contiguous iterators MUST panic.
§Panics
If the iterator is a non-contiguous iterator.
§Safety
Safe as long as the number of the buffer is contains as least as many bytes as the size of V. This must be unimplemented for non-contiguous iterators.