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 returns Some(result)
if the child parser
succeeds,None
if it fails, and Incomplete
if it did not have enough data to decide
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));