pub struct Parser<'input> { /* private fields */ }Expand description
A byte parser that recognizes Patterns
Implementations§
source§impl<'i> Parser<'i>
impl<'i> Parser<'i>
sourcepub fn new(input: &'i [u8]) -> Self
pub fn new(input: &'i [u8]) -> Self
Returns a new instance of Parser that will operate on input
sourcepub fn advance(&mut self, step: usize)
pub fn advance(&mut self, step: usize)
Advances the parser by step. Does nothing if the parser is at the end of the input
sourcepub fn eof(&self) -> bool
pub fn eof(&self) -> bool
Returns true if the parser reached the end of its input. Returns false otherwise
sourcepub fn try_match(&mut self, pattern: impl Pattern) -> Option<&'i [u8]>
pub fn try_match(&mut self, pattern: impl Pattern) -> Option<&'i [u8]>
Tests pattern against the remaining input. If the pattern matches, the matching portion
is returned and the parser is advanced by the length of the matched slice.
Returns None if the pattern does not match.
sourcepub fn assert(&mut self, pattern: impl Pattern) -> &'i [u8] ⓘ
pub fn assert(&mut self, pattern: impl Pattern) -> &'i [u8] ⓘ
Similar to Parser::try_match, but panics if the pattern does not match.
This could be useful when you have previously peeked at the input (perhaps by using
Pattern::test) and later want to advance the parser
Auto Trait Implementations§
impl<'input> RefUnwindSafe for Parser<'input>
impl<'input> Send for Parser<'input>
impl<'input> Sync for Parser<'input>
impl<'input> Unpin for Parser<'input>
impl<'input> UnwindSafe for Parser<'input>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more