Function chomp::combinators::option
[−]
[src]
pub fn option<'a, I, T, E, F>(i: Input<'a, I>, f: F, default: T) -> ParseResult<'a, I, T, E> where I: 'a + Copy, F: FnOnce(Input<'a, I>) -> ParseResult<'a, I, T, E>
Tries the parser f
, on success it yields the parsed value, on failure default
will be
yielded instead.
Incomplete state is propagated. Backtracks on error.
use chomp::{Input, option, token}; let p1 = Input::new(b"abc"); let p2 = Input::new(b"bbc"); assert_eq!(option(p1, |i| token(i, b'a'), b'd').unwrap(), b'a'); assert_eq!(option(p2, |i| token(i, b'a'), b'd').unwrap(), b'd');