13 lines
332 B
Rust
13 lines
332 B
Rust
use crate::parser::{Parser, ParserInput};
|
|
|
|
pub fn optional<P, I, O, E>(parser: P) -> impl Parser<I, Option<O>, E>
|
|
where
|
|
P: Parser<I, O, E>,
|
|
I: ParserInput + Clone,
|
|
{
|
|
move |input: I| match parser.parse(input.clone()) {
|
|
Ok((output, rest)) => Ok((Some(output), rest)),
|
|
Err(_e) => Ok((None, input)),
|
|
}
|
|
}
|