Function winnow::trace::trace

source ·
pub fn trace<I: Stream, O, E>(
    name: impl Display,
    parser: impl Parser<I, O, E>,
) -> impl Parser<I, O, E>
Expand description

Trace the execution of the parser

Note that [Parser::context also provides high level trace information.

See trace module for more details.

§Example

use winnow::trace::trace;

fn short_alpha<'s>(s: &mut &'s [u8]) -> PResult<&'s [u8], InputError<&'s [u8]>> {
  trace("short_alpha",
    take_while(3..=6, AsChar::is_alpha)
  ).parse_next(s)
}

assert_eq!(short_alpha.parse_peek(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
assert_eq!(short_alpha.parse_peek(b"lengthy"), Ok((&b"y"[..], &b"length"[..])));
assert_eq!(short_alpha.parse_peek(b"latin"), Ok((&b""[..], &b"latin"[..])));
assert_eq!(short_alpha.parse_peek(b"ed"), Err(ErrMode::Backtrack(InputError::new(&b"ed"[..], ErrorKind::Slice))));
assert_eq!(short_alpha.parse_peek(b"12345"), Err(ErrMode::Backtrack(InputError::new(&b"12345"[..], ErrorKind::Slice))));