Function fill

Source
pub fn fill<'i, Input, Output, Error, ParseNext>(
    parser: ParseNext,
    buf: &'i mut [Output],
) -> impl Parser<Input, (), Error> + 'i
where 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<'i>(s: &mut &'i str) -> ModalResult<[&'i str; 2]> {
  let mut buf = ["", ""];
  fill("abc", &mut buf).parse_next(s)?;
  Ok(buf)
}

assert_eq!(parser.parse_peek("abcabc"), Ok(("", ["abc", "abc"])));
assert!(parser.parse_peek("abc123").is_err());
assert!(parser.parse_peek("123123").is_err());
assert!(parser.parse_peek("").is_err());
assert_eq!(parser.parse_peek("abcabcabc"), Ok(("abc", ["abc", "abc"])));