Function winnow::combinator::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;

let mut parser = separated_pair("abc", "|", "efg");

assert_eq!(parser.parse_peek("abc|efg"), Ok(("", ("abc", "efg"))));
assert_eq!(parser.parse_peek("abc|efghij"), Ok(("hij", ("abc", "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))));