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: &[u8]) -> IResult<&[u8], &[u8]> {
  trace("short_alpha",
    take_while_m_n(3, 6, AsChar::is_alpha)
  ).parse_next(s)
}

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