Macro nom::expr_res [] [src]

macro_rules! expr_res {
    ($i:expr, $e:expr) => { ... };
}

value!(T, R -> IResult<R, S> ) => R -> IResult<R, T>

or value!(T) => R -> IResult<R, T>

If the child parser was successful, return the value. If no child parser is provided, always return the value

 named!(x<u8>, value!(42, delimited!(tag!("<!--"), take!(5), tag!("-->"))));
 named!(y<u8>, delimited!(tag!("<!--"), value!(42), tag!("-->")));
 let r = x(&b"<!-- abc --> aaa"[..]);
 assert_eq!(r, Done(&b" aaa"[..], 42));

 let r2 = y(&b"<!----> aaa"[..]);
 assert_eq!(r2, Done(&b" aaa"[..], 42));

expr_res!(Result<E,O>) => I -> IResult<I, O> evaluate an expression that returns a Result and returns a IResult::Done(I,T) if Ok

See expr_opt for an example