Function bparse::optional

source ·
pub const fn optional<P: Pattern>(pattern: P) -> Optional<P>
Expand description

Expresses an optional pattern

Returns a new pattern that will always match the input regardless of the outcome of matching self

§Example

use bparse::{Pattern, optional};

let input1 = b"aab";
let input2 = b"aa";

let pattern = "aa".and(optional("b"));

assert_eq!(b"aab", pattern.test(input1).unwrap().0);
assert_eq!(b"aa", pattern.test(input2).unwrap().0);