duesee / abnf-core

A nom-based ABNF core rules parser.
Apache License 2.0
0 stars 4 forks source link

strongly typed ? #16

Open Stargateur opened 3 years ago

Stargateur commented 3 years ago

Should we consider make the parser strongly typed:

#[repr(transparent)]
struct Alpha {
    c: char,
}

pub fn alpha<I, E>(input: I) -> IResult<I, Alpha, E>
where
    I: InputIter + Slice<RangeFrom<usize>>,
    <I as InputIter>::Item: AsChar,
    E: ParseError<I>,
{
    let (input, c) = satisfy(is_alpha)(input)?;

    Ok((input, Alpha { c }))
}

Pro:

Con:

Maybe as a feature ?

duesee commented 3 years ago

I like the idea, but I am not sure on which level of abstraction this makes sense. I used this technique in another crate (imap-codec) and ended up with multiple string types e.g. IString, NString, Atom, ..., which were really useful, but created a lot boilerplate.

I think it is a powerful technique to increase the reliability of a library. But if we want to do that, I would propose to play around with it and see how well it works out. Maybe we could test how another library based on abnf-core, e.g., the abnf crate, would feel like using the typesafe variant?