Function preceded

Source
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;

fn parser<'i>(input: &mut &'i str) -> ModalResult<&'i str> {
    preceded("abc", "efg").parse_next(input)
}

assert_eq!(parser.parse_peek("abcefg"), Ok(("", "efg")));
assert_eq!(parser.parse_peek("abcefghij"), Ok(("hij", "efg")));
assert!(parser.parse_peek("").is_err());
assert!(parser.parse_peek("123").is_err());