pub struct SliceReader<'buf> { /* private fields */ }Expand description
Wraps a slice of bytes with a movable cursor.
The cursor is moved when parsing Patterns.
Implementations§
Source§impl<'b> SliceReader<'b>
impl<'b> SliceReader<'b>
Sourcepub fn parse(&mut self, pattern: impl Pattern) -> Option<&'b [u8]>
pub fn parse(&mut self, pattern: impl Pattern) -> Option<&'b [u8]>
Tests pattern against the elements at the reader’s current position.
If the pattern matches, the cursor is moved, and the matching elements are returned.
Sourcepub fn iter<'i, P: Pattern>(
&'i mut self,
pattern: P,
) -> ItemMatchIterMut<'i, 'b, P>
pub fn iter<'i, P: Pattern>( &'i mut self, pattern: P, ) -> ItemMatchIterMut<'i, 'b, P>
Returns an iterator that repeatedly tests pattern against the input until it stops matching.
Advancing the iterator also advances the cursor.
Sourcepub fn parse_delimited<L, R>(&mut self, left: L, right: R) -> Option<&'b [u8]>
pub fn parse_delimited<L, R>(&mut self, left: L, right: R) -> Option<&'b [u8]>
Extracts the slice delimited by the given patterns.
The cursor is set to right after the right match, and the bytes between the left and right matches are returned.
Returns None if left does not match.
Returns None if no match for right is found after left
Sourcepub fn take_until(&mut self, pattern: impl Pattern) -> Option<&'b [u8]>
pub fn take_until(&mut self, pattern: impl Pattern) -> Option<&'b [u8]>
Advances the cursor until the pattern matches.
The cursor is set right before the match, and the elements leading up to the match are returned.
Returns None if the end of input is reached before pattern can be matched.
Sourcepub fn accept(&mut self, pattern: impl Pattern) -> bool
pub fn accept(&mut self, pattern: impl Pattern) -> bool
Tests the pattern against the elements at the reader’s current position.
If the pattern matches, the cursor is moved and the function returns true.
Sourcepub fn peek(&mut self, pattern: impl Pattern) -> bool
pub fn peek(&mut self, pattern: impl Pattern) -> bool
Like SliceReader::accept, but the cursor is not moved after a successful match.