Function winnow::combinator::terminated

source ·
pub fn terminated<Input, Output, Ignored, Error, ParseNext, IgnoredParser>(
    parser: ParseNext,
    ignored: IgnoredParser
) -> impl Parser<Input, Output, Error>
where Input: Stream, Error: ParserError<Input>, ParseNext: Parser<Input, Output, Error>, IgnoredParser: Parser<Input, Ignored, Error>,
Expand description

Sequence two parsers, only returning the output of the first.

See also seq to generalize this across any number of fields.

§Example

use winnow::combinator::terminated;

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))));