pub fn terminated<Input, Output, Ignored, Error, ParseNext, IgnoredParser>(
parser: ParseNext,
ignored: IgnoredParser,
) -> impl Parser<Input, Output, Error>where
Input: Stream,
Error: ParserError<Input>,
ParseNext: Parser<Input, Output, Error>,
IgnoredParser: Parser<Input, Ignored, Error>,
Expand description
Sequence two parsers, only returning the output of the first.
See also seq
to generalize this across any number of fields.
§Example
use winnow::combinator::terminated;
fn parser<'i>(input: &mut &'i str) -> ModalResult<&'i str> {
terminated("abc", "efg").parse_next(input)
}
assert_eq!(parser.parse_peek("abcefg"), Ok(("", "abc")));
assert_eq!(parser.parse_peek("abcefghij"), Ok(("hij", "abc")));
assert!(parser.parse_peek("").is_err());
assert!(parser.parse_peek("123").is_err());