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