Skip to content

Commit

Permalink
fix(parser): Switch u8 from one_of to literal
Browse files Browse the repository at this point in the history
Based on how `char` went, I figured we will likely see similar.

Fixes #427

BREAKING CHANGE: `u8` parers now  require `I: Compare<u8>`
  • Loading branch information
epage committed Feb 7, 2024
1 parent 842c38f commit 040aede
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,19 +727,20 @@ where
/// b'a'.parse_next(i)
/// }
/// assert_eq!(parser.parse_peek(&b"abc"[..]), Ok((&b"bc"[..], b'a')));
/// assert_eq!(parser.parse_peek(&b" abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b" abc"[..], ErrorKind::Verify))));
/// assert_eq!(parser.parse_peek(&b"bc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"bc"[..], ErrorKind::Verify))));
/// assert_eq!(parser.parse_peek(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&b""[..], ErrorKind::Token))));
/// assert_eq!(parser.parse_peek(&b" abc"[..]), Err(ErrMode::Backtrack(InputError::new(&b" abc"[..], ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek(&b"bc"[..]), Err(ErrMode::Backtrack(InputError::new(&b"bc"[..], ErrorKind::Tag))));
/// assert_eq!(parser.parse_peek(&b""[..]), Err(ErrMode::Backtrack(InputError::new(&b""[..], ErrorKind::Tag))));
/// ```
impl<I, E> Parser<I, u8, E> for u8
where
I: StreamIsPartial,
I: Stream<Token = u8>,
I: Stream,
I: Compare<u8>,
E: ParserError<I>,
{
#[inline(always)]
fn parse_next(&mut self, i: &mut I) -> PResult<u8, E> {
crate::token::one_of(*self).parse_next(i)
crate::token::literal(*self).value(*self).parse_next(i)

Check warning on line 743 in src/parser.rs

View check run for this annotation

Codecov / codecov/patch

src/parser.rs#L743

Added line #L743 was not covered by tests
}
}

Expand Down

0 comments on commit 040aede

Please sign in to comment.