pub fn replace<'a, Toks, T, A, P, B>(
p: P,
value: B,
) -> impl Parser<'a, Toks, T, B>
Expand description
Replaces the returned value of a successful parse with the given value.
When p
successfully parses a value, it is replaced with another arbitrary value.
B
is required to implement Clone
because the parser can run multiple times and must
be able to produce the same value each time.
ยงExamples:
use bad_parsers::{Parser, token};
let p = token('a').replace(42);
assert_eq!(("", 42), p.parse("a").unwrap());
assert!(p.parse("b").is_err());