pub fn preceded<Input, Ignored, Output, Error, IgnoredParser, ParseNext>(
ignored: IgnoredParser,
parser: ParseNext,
) -> impl Parser<Input, Output, Error>where
Input: Stream,
Error: ParserError<Input>,
IgnoredParser: Parser<Input, Ignored, Error>,
ParseNext: Parser<Input, Output, Error>,
Expand description
Sequence two parsers, only returning the output from the second.
See also seq
to generalize this across any number of fields.
ยงExample
use winnow::combinator::preceded;
let mut parser = preceded("abc", "efg");
assert_eq!(parser.parse_peek("abcefg"), Ok(("", "efg")));
assert_eq!(parser.parse_peek("abcefghij"), Ok(("hij", "efg")));
assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
assert_eq!(parser.parse_peek("123"), Err(ErrMode::Backtrack(InputError::new("123", ErrorKind::Tag))));