diff --git a/src/combinator/mod.rs b/src/combinator/mod.rs index fe6655b9..14ae0796 100644 --- a/src/combinator/mod.rs +++ b/src/combinator/mod.rs @@ -564,7 +564,30 @@ pub fn value, F>( where F: Parser, { - parser.map(move |_| val.clone()) + Value { val, parser } +} + +/// Parser implementation for [value] +pub struct Value { + parser: F, + val: O1, +} + +impl Parser for Value +where + F: Parser, + O1: Clone, + E: ParseError, +{ + type Output = O1; + type Error = E; + fn process( + &mut self, + input: I, + ) -> PResult { + self.parser.process::>(input) + .map(|(i, _)| ( i, OM::Output::bind(|| self.val.clone()) )) + } } /// Succeeds if the child parser returns an error.