Function combine::optional[][src]

pub fn optional<Input, P>(parser: P) -> Optional<P> where
    Input: Stream,
    P: Parser<Input>, 
Expand description

Parses parser and outputs Some(value) if it succeeds, None if it fails without consuming any input. Fails if parser fails after having committed some input.

let mut parser = optional(string("hello"));
assert_eq!(parser.parse("hello"), Ok((Some("hello"), "")));
assert_eq!(parser.parse("world"), Ok((None, "world")));
assert!(parser.parse("heya").is_err());