pub fn pair<I, O1, O2, E: ParseError<I>, F, G>(
first: F,
second: G,
) -> impl Parser<I, Output = (O1, O2), Error = E>
Expand description
Gets an object from the first parser, then gets another object from the second parser.
§Arguments
first
The first parser to apply.second
The second parser to apply.
§Example
use nom::sequence::pair;
use nom::bytes::complete::tag;
use nom::{error::ErrorKind, Err, Parser};
let mut parser = pair(tag("abc"), tag("efg"));
assert_eq!(parser.parse("abcefg"), Ok(("", ("abc", "efg"))));
assert_eq!(parser.parse("abcefghij"), Ok(("hij", ("abc", "efg"))));
assert_eq!(parser.parse(""), Err(Err::Error(("", ErrorKind::Tag))));
assert_eq!(parser.parse("123"), Err(Err::Error(("123", ErrorKind::Tag))));