Skip to main content

separated_pair

Function separated_pair 

Source
pub fn separated_pair<Input, Output1, Sep, Output2, Error, Parser1, SepParser, Parser2>(
    first: Parser1,
    sep: SepParser,
    second: Parser2,
) -> impl Parser<Input, (Output1, Output2), Error>
where Input: Stream, Error: ParserError<Input>, Parser1: Parser<Input, Output1, Error>, SepParser: Parser<Input, Sep, Error>, Parser2: Parser<Input, Output2, 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());