[][src]Macro cron_clock::cond_reduce

macro_rules! cond_reduce {
    ($i:expr, $cond:expr, $submac:ident!( $($args:tt)* )) => { ... };
    ($i:expr, $cond:expr, $f:expr) => { ... };
}

cond_reduce!(bool, I -> IResult<I,O>) => I -> IResult<I, O> Conditional combinator with error

Wraps another parser and calls it if the condition is met. This combinator returns an error if the condition is false

This is especially useful if a parser depends on the value returned by a preceding parser in a do_parse!.

 let b = true;
 let f = closure!(&'static[u8],
   cond_reduce!( b, tag!("abcd") )
 );

 let a = b"abcdef";
 assert_eq!(f(&a[..]), Ok((&b"ef"[..], &b"abcd"[..])));

 let b2 = false;
 let f2 = closure!(&'static[u8],
   cond_reduce!( b2, tag!("abcd") )
 );
 assert_eq!(f2(&a[..]), Err(Err::Error(error_position!(&a[..], ErrorKind::CondReduce))));