feat: impl From<ExpectedNumber> for RichPattern
Currently it is not possible to use the number::Number parsers with the Rich error type as RichPattern does not implement From<ExpectedNumber>.
This PR adds the missing impl in the number module so it is appropriatley feature gated.
Not previously possible:
fn parse_u8<'a>() -> impl Parser<'a, &'a str, u8, extra::Err<Rich<'a, char>>> {
let u8_num: Number<STANDARD, &'a str, u8, ErrRich<'a>> = number();
u8_num
}
I'm not exactly sure what variant of RichPattern to use here, Label seemed the most fitting but then I'm not sure on the label name.
Open to suggestions better than "number".
Thanks! I think adding a new variant to RichPattern is fine also, and might be worth it for the ability to disambiguate at a type level (we don't want end users pattern-matching on strings, if we can help it). If you could, also added #[non_exhaustive] to the enum would also be great. It's a breaking change, but there are already several of those lined up anyway!
Thanks! I think adding a new variant to
RichPatternis fine also...
How would you like that to work feature wise? If we added RichPattern::Number it wouldn't really make sense if a user wasn't using the lexical-numbers feature.
Apologies, GitHub swallowed the notification for this.
I think the only change needed is to add #[non_exhaustive] to the RichPattern enum.