Struct toad_cursor::Cursor
source · pub struct Cursor<T> { /* private fields */ }
Expand description
A cursor over a byte array (std- and alloc-less port of std::io::Cursor
)
Implementations§
source§impl<T: AsRef<[u8]>> Cursor<T>
impl<T: AsRef<[u8]>> Cursor<T>
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwraps the cursor, discarding its internal position
sourcepub fn next(&mut self) -> Option<u8>
pub fn next(&mut self) -> Option<u8>
Take the next byte in the cursor, returning None if the cursor is exhausted.
Runs in O(1) time.
sourcepub fn take(&mut self, n: usize) -> &[u8] ⓘ
pub fn take(&mut self, n: usize) -> &[u8] ⓘ
Take n
bytes from the cursor, stopping early if
the end of the buffer is encountered.
Runs in O(1) time.
sourcepub fn take_exact(&mut self, n: usize) -> Option<&[u8]>
pub fn take_exact(&mut self, n: usize) -> Option<&[u8]>
Take n
bytes from the cursor, returning None if
the end of the buffer is encountered.
Runs in O(1) time.
sourcepub fn peek(&self, n: usize) -> &[u8] ⓘ
pub fn peek(&self, n: usize) -> &[u8] ⓘ
Without advancing the position, look at the next
n
bytes, or until the end if there are less than n
bytes
remaining.
Runs in O(1) time.
sourcepub fn peek_exact(&self, n: usize) -> Option<&[u8]>
pub fn peek_exact(&self, n: usize) -> Option<&[u8]>
Without advancing the position, look at the next
n
bytes, returning None if there are less than n
bytes
remaining.
Runs in O(1) time.
sourcepub fn skip(&mut self, n: usize) -> usize
pub fn skip(&mut self, n: usize) -> usize
Advance the cursor by n
bytes.
Returns the actual number of bytes skipped:
- Equal to n if there are at least n more bytes in the buffer
- Less than n if n would seek past the end
- Zero if the cursor is already exhausted
Runs in O(1) time.
sourcepub fn take_while(&mut self, f: impl FnMut(u8) -> bool) -> &[u8] ⓘ
pub fn take_while(&mut self, f: impl FnMut(u8) -> bool) -> &[u8] ⓘ
Consume bytes until a predicate returns false
or the end is reached.
Runs in O(n) time.
sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Whether the cursor has reached the end of the buffer.
Runs in O(1) time.
sourcepub fn peek_until_end(&self) -> &[u8] ⓘ
pub fn peek_until_end(&self) -> &[u8] ⓘ
Get the bytes remaining in the buffer without advancing the position.
Runs in O(1) time.
sourcepub fn take_until_end(&mut self) -> &[u8] ⓘ
pub fn take_until_end(&mut self) -> &[u8] ⓘ
Get the bytes remaining in the buffer, advancing the position to the end.
Runs in O(1) time.
Trait Implementations§
source§impl<T: Ord> Ord for Cursor<T>
impl<T: Ord> Ord for Cursor<T>
source§impl<T: PartialEq> PartialEq<Cursor<T>> for Cursor<T>
impl<T: PartialEq> PartialEq<Cursor<T>> for Cursor<T>
source§impl<T: PartialOrd> PartialOrd<Cursor<T>> for Cursor<T>
impl<T: PartialOrd> PartialOrd<Cursor<T>> for Cursor<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more