summaryrefslogtreecommitdiff
path: root/crates/parseable/src/lib.rs
blob: 38ed418984dae92bd36d882d61323dde37703ff7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#![feature(impl_trait_in_assoc_type)]

use mon::{Parser, input::{Input, InputIter}};

pub trait Parseable<'a, I: Input + 'a> {
    type Parser: Parser<I, Output = Self>;

    fn parser() -> Self::Parser;

    fn parse(input: I) -> Result<Self, I>
    where
        Self: Sized,
    {
        Self::parser()
            .parse_finished(InputIter::new(input))
            .map_err(|e| e.rest())
    }
}