Function chomp::parsers::take_while [] [src]

pub fn take_while<I: Input, F>(i: I, f: F) -> SimpleResult<I, I::Buffer> where
    F: FnMut(I::Token) -> bool

Matches all items while f returns false, returns a slice of all the matched items.

If no failure can be found the parser will be considered to be incomplete as there might be more input which needs to be matched.

use chomp::prelude::{parse_only, take_while};

let r = parse_only(|i| take_while(i, |c| c == b'a' || c == b'b'), b"abcdcba");

assert_eq!(r, Ok(&b"ab"[..]));

Without managing to match anything:

use chomp::prelude::{parse_only, take_while};

let r = parse_only(|i| take_while(i, |c| c == b'z'), b"abcdcba");

assert_eq!(r, Ok(&b""[..]));