[][src]Function combine::try

pub fn try<P>(p: P) -> Try<P> where
    P: Parser
Deprecated since 3.5.2:

try is a reserved keyword in Rust 2018. Use attempt instead.

try(p) behaves as p except it acts as if the parser hadn't consumed any input if p fails after consuming input.

let mut p = try(string("let"))
    .or(string("lex"));
let result = p.parse("lex").map(|x| x.0);
assert_eq!(result, Ok("lex"));
let result = p.parse("aet").map(|x| x.0);
assert!(result.is_err());

Note: if you're on the 2018 edition, you'll need to either use r#try, or attempt