check

Function check 

Source
pub fn check<CheckItem, Input, ClosureOutput>(
    closure: CheckItem,
) -> SingleCheckParser<CheckItem, Input, ClosureOutput>
where CheckItem: Fn(Input) -> ClosureOutput, ClosureOutput: OptionOrBool,
Expand description

Check single item with the given closure.

The closure must be either of: Fn(Iterator::Item) -> Option<NewOutput> or Fn(Iterator::Item) -> bool.

If the closure returns Option<NewOutput>, the output will be (NewOutput,). If the closure returns bool, the output will be ().

ยงExample

use rusty_parser as rp;
use rp::IntoParser;

// `check` returns by Option<>
let parser = rp::check( |ch:char| if ch.is_alphabetic() { Some(ch) } else { None } );
let res = rp::parse( &parser, "hello".chars() );

// `check` returns by bool
let parser = rp::check( |ch:i32| if ch == 1 { true }else{ false } );
let res = rp::parse( &parser, (&[1,2,3]).iter().cloned() );