pub fn fill<'a, I, O, E, F>(f: F, buf: &'a mut [O]) -> impl Parser<I, (), E> + 'awhere
I: Stream + 'a,
F: Parser<I, O, E> + 'a,
E: ParseError<I> + 'a,Expand description
Runs the embedded parser repeatedly, filling the given slice with results.
This parser fails if the input runs out before the given slice is full.
Arguments
fThe parser to apply.bufThe slice to fill
Example
use winnow::multi::fill;
use winnow::bytes::tag;
fn parser(s: &str) -> IResult<&str, [&str; 2]> {
let mut buf = ["", ""];
let (rest, ()) = fill("abc", &mut buf).parse_next(s)?;
Ok((rest, buf))
}
assert_eq!(parser("abcabc"), Ok(("", ["abc", "abc"])));
assert_eq!(parser("abc123"), Err(ErrMode::Backtrack(Error::new("123", ErrorKind::Tag))));
assert_eq!(parser("123123"), Err(ErrMode::Backtrack(Error::new("123123", ErrorKind::Tag))));
assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
assert_eq!(parser("abcabcabc"), Ok(("abc", ["abc", "abc"])));