Function byte_parser::parse_iter[][src]

pub fn parse_iter<'s, I, F, O>(i: I, f: F) -> ParseIter<I, F>

Notable traits for ParseIter<I, F>

impl<'s, I, F, O> Iterator for ParseIter<I, F> where
    I: ParseIterator<'s>,
    F: FnMut(&mut I) -> Option<O>, 
type Item = O;
where
    I: ParseIterator<'s>,
    F: FnMut(&mut I) -> Option<O>, 
This is supported on crate feature unstable-parse-iter only.

From a ParseIterator generate an Iterator.

Example parsing arguments

fn args(arg_str: &str) -> impl Iterator<Item=&str> {
	parse_iter(
		StrParser::new(arg_str),
		|parser| {

			// if we are in a string
			if parser.advance_if(|&b| b == b'\'')? {
				let s = parser.record()
					.while_byte_fn(|&b| b != b'\'')
					.consume_to_str();

				// consume the ending ' and
				// if a space follows consume it to
				parser.advance();
				parser.advance_if(|&b| b == b' ');
				return Some(s)
			}

			// consume until a whitespace or an '
			let s = parser.record()
				.while_byte_fn(|&b| !matches!(b, b' ' | b'\''))
				.consume_to_str();
 			
			// skip an empty space
			parser.advance_if(|&b| b == b' ');
 
			Some(s)
		}
	)
}
 
let args: Vec<_> = args("arg1 'arg 2' arg3'arg 4'arg5").collect();
assert_eq!(args, ["arg1", "arg 2", "arg3", "arg 4", "arg5"]);