winnow::combinator

Function separated_pair

Source
pub fn separated_pair<Input, O1, Sep, O2, Error, P1, SepParser, P2>(
    first: P1,
    sep: SepParser,
    second: P2,
) -> impl Parser<Input, (O1, O2), Error>
where Input: Stream, Error: ParserError<Input>, P1: Parser<Input, O1, Error>, SepParser: Parser<Input, Sep, Error>, P2: Parser<Input, O2, Error>,
Expand description

Sequence three parsers, only returning the values of the first and third.

See also seq to generalize this across any number of fields.

§Example

use winnow::combinator::separated_pair;

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

assert_eq!(parser.parse_peek("abc|efg"), Ok(("", ("abc", "efg"))));
assert_eq!(parser.parse_peek("abc|efghij"), Ok(("hij", ("abc", "efg"))));
assert!(parser.parse_peek("").is_err());
assert!(parser.parse_peek("123").is_err());