Trait lexical_util::iterator::DigitsIter
source · pub trait DigitsIter<'a>: Iterator<Item = &'a u8> + Iter<'a> {
// Required methods
fn peek(&mut self) -> Option<Self::Item>;
fn is_digit(&self, value: u8) -> bool;
// Provided methods
fn is_consumed(&mut self) -> bool { ... }
fn try_read(&mut self) -> Option<Self::Item> { ... }
fn peek_is_cased(&mut self, value: u8) -> bool { ... }
fn peek_is_uncased(&mut self, value: u8) -> bool { ... }
fn peek_is(&mut self, value: u8, is_cased: bool) -> bool { ... }
fn read_if<Pred: FnOnce(u8) -> bool>(&mut self, pred: Pred) -> Option<u8> { ... }
fn read_if_value_cased(&mut self, value: u8) -> Option<u8> { ... }
fn read_if_value_uncased(&mut self, value: u8) -> Option<u8> { ... }
fn read_if_value(&mut self, value: u8, is_cased: bool) -> Option<u8> { ... }
fn skip_zeros(&mut self) -> usize { ... }
}
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 Methods§
Provided Methods§
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.
If this is an iterator, this is based on the number of items left to be returned. We do not necessarly know the length of the buffer. If this is a non-contiguous iterator, this MUST advance the state until it knows a value can be returned.
Any incorrect implementations of this affect all safety invariants
for the rest of the trait. For contiguous iterators, this can be
as simple as checking if self.cursor >= self.slc.len()
, but for
non-contiguous iterators you MUST advance to the next element
to be returned, then check to see if a value exists. The safest
implementation is always to check if self.peek().is_none()
and
ensure peek is always safe.
If you would like to see if the cursor is at the end of the buffer, see is_buffer_empty instead.
sourcefn try_read(&mut self) -> Option<Self::Item>
fn try_read(&mut self) -> Option<Self::Item>
Peek the next value of the iterator, and step only if it exists.
sourcefn peek_is_cased(&mut self, value: u8) -> bool
fn peek_is_cased(&mut self, value: u8) -> bool
Check if the next element is a given value.
sourcefn peek_is_uncased(&mut self, value: u8) -> bool
fn peek_is_uncased(&mut self, value: u8) -> bool
Check if the next element is a given value without case sensitivity.
sourcefn peek_is(&mut self, value: u8, is_cased: bool) -> bool
fn peek_is(&mut self, value: u8, is_cased: bool) -> bool
Check if the next element is a given value with optional case sensitivity.
sourcefn read_if<Pred: FnOnce(u8) -> bool>(&mut self, pred: Pred) -> Option<u8>
fn read_if<Pred: FnOnce(u8) -> bool>(&mut self, pred: Pred) -> Option<u8>
Peek the next value and consume it if the read value matches the expected one.
sourcefn read_if_value_cased(&mut self, value: u8) -> Option<u8>
fn read_if_value_cased(&mut self, value: u8) -> Option<u8>
Read a value if the value matches the provided one.
sourcefn read_if_value_uncased(&mut self, value: u8) -> Option<u8>
fn read_if_value_uncased(&mut self, value: u8) -> Option<u8>
Read a value if the value matches the provided one without case sensitivity.
sourcefn read_if_value(&mut self, value: u8, is_cased: bool) -> Option<u8>
fn read_if_value(&mut self, value: u8, is_cased: bool) -> Option<u8>
Read a value if the value matches the provided one.
sourcefn skip_zeros(&mut self) -> usize
fn skip_zeros(&mut self) -> usize
Skip zeros from the start of the iterator