devela::_dep::winnow::combinator

Function peek

pub fn peek<Input, Output, Error, ParseNext>(
    parser: ParseNext,
) -> impl Parser<Input, Output, Error>
where Input: Stream, Error: ParserError<Input>, ParseNext: Parser<Input, Output, Error>,
Available on crate feature dep_winnow only.
Expand description

Apply the parser without advancing the input.

To lookahead and only advance on success, see opt.

ยงExample

use winnow::combinator::peek;
use winnow::ascii::alpha1;

let mut parser = peek(alpha1);

assert_eq!(parser.parse_peek("abcd;"), Ok(("abcd;", "abcd")));
assert_eq!(parser.parse_peek("123;"), Err(ErrMode::Backtrack(InputError::new("123;", ErrorKind::Slice))));