pub trait DigitsIter<'a>: Iterator<Item = &'a u8> + Iter<'a> {
Show 13 methods
// Required methods
fn increment_count(&mut self);
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§
Sourcefn increment_count(&mut self)
fn increment_count(&mut self)
Increment the number of digits that have been returned by the iterator.
For contiguous iterators, this is a no-op. For non-contiguous iterators, this increments the count by 1.
Sourcefn peek(&mut self) -> Option<Self::Item>
fn peek(&mut self) -> Option<Self::Item>
Peek the next value of the iterator, without consuming it.
Note that this can modify the internal state, by skipping digits for iterators that find the first non-zero value, etc. We optimize this for the case where we have contiguous iterators, since non-contiguous iterators already have a major performance penalty.
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
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.