Function winnow::combinator::iterator
source · pub fn iterator<I, O, E, F>(input: I, parser: F) -> ParserIterator<F, I, O, E> ⓘ
Expand description
Repeats the embedded parser, lazily returning the results
Call the iterator’s ParserIterator::finish
method to get the remaining input if successful,
or the error value if we encountered an error.
On ErrMode::Backtrack
, iteration will stop. To instead chain an error up, see cut_err
.
§Example
use winnow::{combinator::iterator, IResult, token::tag, ascii::alpha1, combinator::terminated};
use std::collections::HashMap;
let data = "abc|defg|hijkl|mnopqr|123";
let mut it = iterator(data, terminated(alpha1, "|"));
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", ())));