pub fn trace<I: Stream, O, E: ParserError<I>>(
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 [tutorial][crate::_tutorial::chapter_8] for more details.
§Example
use winnow::combinator::trace;
fn short_alpha<'s>(s: &mut &'s [u8]) -> ModalResult<&'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!(short_alpha.parse_peek(b"ed").is_err());
assert!(short_alpha.parse_peek(b"12345").is_err());