nom::opt_res
[−]
[src]
macro_rules! opt_res { ($i:expr, $submac:ident!( $($args:tt)* )) => { ... }; ($i:expr, $f:expr) => { ... }; }
opt_res!(I -> IResult<I,O>) => I -> IResult<I, Result<nom::Err,O>>
make the underlying parser optional
returns a Result, with Err containing the parsing error
named!( o<&[u8], Result<&[u8], nom::Err<&[u8]> > >, opt_res!( tag!( "abcd" ) ) ); let a = b"abcdef"; let b = b"bcdefg"; assert_eq!(o(&a[..]), Done(&b"ef"[..], Ok(&b"abcd"[..]))); assert_eq!(o(&b[..]), Done(&b"bcdefg"[..], Err(Position(ErrorKind::Tag, &b[..]))));