Boxed parser
This commit is contained in:
parent
0c6c59da07
commit
d707249904
21
src/lib.rs
21
src/lib.rs
@ -8,6 +8,27 @@ trait Parser<I, O, E> {
|
|||||||
fn parse(&self, input: I) -> ParseResult<I, O, E>;
|
fn parse(&self, input: I) -> ParseResult<I, O, E>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct BoxedParser<I, O, E> {
|
||||||
|
inner: Box<dyn Parser<I, O, E>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I, O, E> BoxedParser<I, O, E> {
|
||||||
|
fn new<P>(inner: P) -> Self
|
||||||
|
where
|
||||||
|
P: Parser<I, O, E> + 'static,
|
||||||
|
{
|
||||||
|
BoxedParser {
|
||||||
|
inner: Box::new(inner),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I, O, E> Parser<I, O, E> for BoxedParser<I, O, E> {
|
||||||
|
fn parse(&self, input: I) -> ParseResult<I, O, E> {
|
||||||
|
self.inner.parse(input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<I, O, E, F> Parser<I, O, E> for F
|
impl<I, O, E, F> Parser<I, O, E> for F
|
||||||
where
|
where
|
||||||
F: Fn(I) -> ParseResult<I, O, E>,
|
F: Fn(I) -> ParseResult<I, O, E>,
|
||||||
|
Loading…
Reference in New Issue
Block a user