diff --git a/src/combinator/mod.rs b/src/combinator/mod.rs index fe6655b98..98b806db6 100644 --- a/src/combinator/mod.rs +++ b/src/combinator/mod.rs @@ -562,9 +562,34 @@ pub fn value, F>( parser: F, ) -> impl Parser where + I: Input, F: Parser, { - parser.map(move |_| val.clone()) + Value { parser, val } +} + +/// Parser implementation for [value] +pub struct Value { + parser: F, + val: O1, +} + +impl Parser for Value +where + I: Input, + F: Parser, + O1: Clone, +{ + type Output = O1; + type Error = >::Error; + + fn process(&mut self, input: I) -> PResult { + let (input, ()) = self + .parser + .process::>(input)?; + + Ok((input, OM::Output::bind(|| self.val.clone()))) + } } /// Succeeds if the child parser returns an error.