mirror of
https://github.com/rust-lang/rust
synced 2024-11-05 20:45:15 +00:00
20 lines
488 B
Rust
20 lines
488 B
Rust
// check-pass
|
|
#![allow(dead_code)]
|
|
struct Parser<'a, I, O> {
|
|
parse: Box<dyn FnMut(I) -> Result<O, String> + 'a>
|
|
}
|
|
|
|
impl<'a, I: 'a, O: 'a> Parser<'a, I, O> {
|
|
fn compose<K: 'a>(mut self, mut rhs: Parser<'a, O, K>) -> Parser<'a, I, K> {
|
|
Parser {
|
|
parse: Box::new(move |x: I| {
|
|
match (self.parse)(x) {
|
|
Ok(r) => (rhs.parse)(r),
|
|
Err(e) => Err(e)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
fn main() {}
|