Function nom::combinator::iterator [−][src]
pub fn iterator<Input, Output, Error, F>(
input: Input,
f: F
) -> ParserIterator<Input, Error, F>ⓘwhereNotable traits for &'a mut ParserIterator<Input, Error, F>
impl<'a, Input, Output, Error, F> Iterator for &'a mut ParserIterator<Input, Error, F> where
F: Fn(Input) -> IResult<Input, Output, Error>,
Input: Clone, type Item = Output;
F: Fn(Input) -> IResult<Input, Output, Error>,
Error: ParseError<Input>,
creates an iterator from input data and a parser
call the iterator’s [finish] method to get the remaining input if successful, or the error value if we encountered an error
use nom::{combinator::iterator, IResult, bytes::complete::tag, character::complete::alpha1, sequence::terminated}; use std::collections::HashMap; let data = "abc|defg|hijkl|mnopqr|123"; let mut it = iterator(data, terminated(alpha1, tag("|"))); let parsed = it.map(|v| (v, v.len())).collect::<HashMap<_,_>>(); let res: IResult<_,_> = it.finish(); assert_eq!(parsed, [("abc", 3usize), ("defg", 4), ("hijkl", 5), ("mnopqr", 6)].iter().cloned().collect()); assert_eq!(res, Ok(("123", ())));