Struct toad_common::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
sourceimpl<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]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn take(&mut self, n: usize) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [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]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn peek(&self, n: usize) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [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]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn take_while(&mut self, f: impl FnMut(u8) -> bool) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Consume bytes until a predicate returns false.
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]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn peek_until_end(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Get the bytes remaining in the buffer without advancing the position.
Runs in O(1) time.
Trait Implementations
sourceimpl<T: Ord> Ord for Cursor<T>
impl<T: Ord> Ord for Cursor<T>
1.21.0 · sourceconst fn max(self, other: Self) -> Self
const fn max(self, other: Self) -> Self
1.21.0 · sourceconst fn min(self, other: Self) -> Self
const fn min(self, other: Self) -> Self
1.50.0 · sourceconst fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
const fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl<T: PartialEq> PartialEq<Cursor<T>> for Cursor<T>
impl<T: PartialEq> PartialEq<Cursor<T>> for Cursor<T>
sourceimpl<T: PartialOrd> PartialOrd<Cursor<T>> for Cursor<T>
impl<T: PartialOrd> PartialOrd<Cursor<T>> for Cursor<T>
sourcefn partial_cmp(&self, other: &Cursor<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &Cursor<T>) -> Option<Ordering>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more