Function nom::combinator::opt [−][src]
pub fn opt<I: Clone, O, E: ParseError<I>, F>(
f: F
) -> impl Fn(I) -> IResult<I, Option<O>, E> where
F: Fn(I) -> IResult<I, O, E>,
optional parser: will return None if not successful
use nom::combinator::opt; use nom::character::complete::alpha1; fn parser(i: &str) -> IResult<&str, Option<&str>> { opt(alpha1)(i) } assert_eq!(parser("abcd;"), Ok((";", Some("abcd")))); assert_eq!(parser("123;"), Ok(("123;", None)));