From d707249904caad51dcaed46a5a673b1031df2366 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 16 Oct 2022 00:44:47 -0700 Subject: [PATCH] Boxed parser --- src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 2a8cfdc..602ce57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,27 @@ trait Parser { fn parse(&self, input: I) -> ParseResult; } +struct BoxedParser { + inner: Box>, +} + +impl BoxedParser { + fn new

(inner: P) -> Self + where + P: Parser + 'static, + { + BoxedParser { + inner: Box::new(inner), + } + } +} + +impl Parser for BoxedParser { + fn parse(&self, input: I) -> ParseResult { + self.inner.parse(input) + } +} + impl Parser for F where F: Fn(I) -> ParseResult,