-
Something like this: pub fn my_parser<'s>(input: &mut &'s str) -> PResult<&'s str> {
// matches on "foo"
peek("foo").parse_next(input)
// more here
} let input = "foobar";
let output = my_parser.parse_next(input).unwrap();
assert_eq!(output, "f");
// only one char consumed
assert_eq!(input, "oobar"); Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
epage
Dec 1, 2023
Replies: 1 comment 1 reply
-
pub fn my_parser<'s>(input: &mut &'s str) -> PResult<char> {
let _ = peek("foo").parse_next(input)?;
any.parse_next(input)
} When |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ckoehler
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
peek
will backtrack on lack of success, so you should be able to doWhen
foo
doesn't match, you can do other things likeopt
,alt
, etc.