Function winnow::combinator::iterator

source ·
pub fn iterator<I, O, E, F>(input: I, parser: F) -> ParserIterator<F, I, O, E> where
    F: Parser<I, O, E>,
    I: Stream,
    E: ParseError<I>,
Expand description

Creates an iterator from input data and a parser.

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, bytes::tag, character::alpha1, sequence::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", ())));