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
first
The first parser to apply.second
The second parser to match an object.
§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))));