Function winnow::sequence::terminated
source · pub fn terminated<I, O1, O2, E: ParseError<I>, F, G>(
first: F,
second: G
) -> impl Parser<I, O1, E>where
I: Stream,
F: Parser<I, O1, E>,
G: Parser<I, O2, E>,
Expand description
Apply 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::sequence::terminated;
use winnow::bytes::tag;
let mut parser = terminated("abc", "efg");
assert_eq!(parser.parse_next("abcefg"), Ok(("", "abc")));
assert_eq!(parser.parse_next("abcefghij"), Ok(("hij", "abc")));
assert_eq!(parser.parse_next(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
assert_eq!(parser.parse_next("123"), Err(ErrMode::Backtrack(Error::new("123", ErrorKind::Tag))));