combine::parser::range

Function take_while

Source
pub fn take_while<I, F>(f: F) -> TakeWhile<I, F>
where I: RangeStream, I::Range: Range, F: FnMut(I::Item) -> bool,
Expand description

Zero-copy parser which reads a range of 0 or more tokens which satisfy f.

many is a non-RangeStream alternative.

let mut parser = take_while(|c: char| c.is_digit(10));
let result = parser.parse("123abc");
assert_eq!(result, Ok(("123", "abc")));
let result = parser.parse("abc");
assert_eq!(result, Ok(("", "abc")));