nom::opt! [] [src]

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

opt!(I -> IResult<I,O>) => I -> IResult<I, Option<O>> make the underlying parser optional

returns an Option of the returned type. This parser never fails

 named!( o<&[u8], Option<&[u8]> >, opt!( tag!( "abcd" ) ) );

 let a = b"abcdef";
 let b = b"bcdefg";
 assert_eq!(o(&a[..]), Done(&b"ef"[..], Some(&b"abcd"[..])));
 assert_eq!(o(&b[..]), Done(&b"bcdefg"[..], None));