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.