Function optional

Source
pub fn optional<P>(pattern: P) -> Repetition<P>
where P: Pattern,
Expand description

Returns a new pattern that matches 0 or 1 repetitions of pattern

This implies the new pattern always matches the input.

use bparse::{Pattern, optional};

assert_eq!(optional("a").eval(b"b"), Some(0));
assert_eq!(optional("a").eval(b"a"), Some(1));