Function nom::multi::count [−][src]
pub fn count<I, O, E, F>(
f: F,
count: usize
) -> impl Fn(I) -> IResult<I, Vec<O>, E> where
I: Clone + PartialEq,
F: Fn(I) -> IResult<I, O, E>,
E: ParseError<I>,
Runs the embedded parser a specified number
of times. Returns the results in a Vec
.
Arguments
f
The parser to apply.count
How often to apply the parser.
use nom::multi::count; use nom::bytes::complete::tag; fn parser(s: &str) -> IResult<&str, Vec<&str>> { count(tag("abc"), 2)(s) } assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"]))); assert_eq!(parser("abc123"), Err(Err::Error(("123", ErrorKind::Tag)))); assert_eq!(parser("123123"), Err(Err::Error(("123123", ErrorKind::Tag)))); assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag)))); assert_eq!(parser("abcabcabc"), Ok(("abc", vec!["abc", "abc"])));