pub fn fill<'a, I, E, F>(
parser: F,
buf: &'a mut [<F as Parser<I>>::Output],
) -> impl Parser<I, Output = (), Error = E> + 'aExpand 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
use nom::multi::fill;
use nom::bytes::complete::tag;
fn parser(s: &str) -> IResult<&str, [&str; 2]> {
let mut buf = ["", ""];
let (rest, ()) = fill(tag("abc"), &mut buf).parse(s)?;
Ok((rest, buf))
}
assert_eq!(parser("abcabc"), Ok(("", ["abc", "abc"])));
assert_eq!(parser("abc123"), Err(Err::Error(Error::new("123", ErrorKind::Tag))));
assert_eq!(parser("123123"), Err(Err::Error(Error::new("123123", ErrorKind::Tag))));
assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
assert_eq!(parser("abcabcabc"), Ok(("abc", ["abc", "abc"])));