Function rocket::mtls::x509::der_parser::asn1_rs::nom::combinator::iterator
source · pub fn iterator<Input, Output, Error, F>(
input: Input,
f: F,
) -> ParserIterator<Input, Error, F> ⓘwhere
F: Parser<Input, Output, Error>,
Error: ParseError<Input>,
Available on crate feature
mtls
only.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 Err::Error
, iteration will stop. To instead chain an error up, see cut
.
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", ())));