Function combine::tokens_cmp[][src]

pub fn tokens_cmp<C, T, I>(tokens: T, cmp: C) -> TokensCmp<C, T, I> where
    C: FnMut(T::Item, I::Token) -> bool,
    T: Clone + IntoIterator,
    I: Stream
Expand description

Parses multiple tokens.

Consumes items from the input and compares them to the values from tokens using the comparison function cmp. Succeeds if all the items from tokens are matched in the input stream and fails otherwise.

let result = tokens_cmp("abc".chars(), |l, r| l.eq_ignore_ascii_case(&r))
    .parse("AbC")
    .map(|x| x.0.as_str());
assert_eq!(result, Ok("abc"));
let result = tokens_cmp(
    &b"025"[..],
    |&l, r| (if l < r { r - l } else { l - r }) <= 2,
)
    .parse(&b"123"[..])
    .map(|x| x.0);
assert_eq!(result, Ok(&b"025"[..]));