Function winnow::combinator::iterator

source ·
pub fn iterator<Input, Output, Error, ParseNext>(
    input: Input,
    parser: ParseNext,
) -> ParserIterator<ParseNext, Input, Output, Error> 
where ParseNext: Parser<Input, Output, Error>, Input: Stream, Error: ParserError<Input>,
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, 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", ())));