Function winnow::combinator::terminated
source · pub fn terminated<I, O1, O2, E: ParserError<I>, F, G>(
first: F,
second: G,
) -> impl Parser<I, O1, E>Expand description
Sequence two parsers, only returning the output of the first.
§Arguments
firstThe first parser to apply.secondThe second parser to match an object.
See also seq to generalize this across any number of fields.
§Example
use winnow::combinator::terminated;
use winnow::token::tag;
let mut parser = terminated("abc", "efg");
assert_eq!(parser.parse_peek("abcefg"), Ok(("", "abc")));
assert_eq!(parser.parse_peek("abcefghij"), Ok(("hij", "abc")));
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))));