Function winnow::combinator::fill
source · pub fn fill<'i, Input, Output, Error, ParseNext>(
parser: ParseNext,
buf: &'i mut [Output],
) -> impl Parser<Input, (), Error> + 'iwhere
Input: Stream + 'i,
ParseNext: Parser<Input, Output, Error> + 'i,
Error: ParserError<Input> + 'i,
Expand description
Repeats the embedded parser, filling the given slice with results.
This parser fails if the input runs out before the given slice is full.
§Example
use winnow::combinator::fill;
fn parser(s: &str) -> IResult<&str, [&str; 2]> {
let mut buf = ["", ""];
let (rest, ()) = fill("abc", &mut buf).parse_peek(s)?;
Ok((rest, buf))
}
assert_eq!(parser("abcabc"), Ok(("", ["abc", "abc"])));
assert_eq!(parser("abc123"), Err(ErrMode::Backtrack(InputError::new("123", ErrorKind::Tag))));
assert_eq!(parser("123123"), Err(ErrMode::Backtrack(InputError::new("123123", ErrorKind::Tag))));
assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
assert_eq!(parser("abcabcabc"), Ok(("abc", ["abc", "abc"])));