I've got a data structure that basically looks like:
pub enum Record {
AVariant,
BVariant { x : i32, y : u64, },
CVariant { ... },
}
And I want to be able to parse into this data structure from text-based records that look like:
A Variant
B Variant 1234 12abc
C Variant ...
(Note some of the integer fields are decimal and others are hex. Yes, I know. I didn't pick this format.)
I started writing this in nom, which was fine except for the fact that the code is very repetitive because the enum I'm doing this for has about 100 variants each with 2-5 fields on average. But at least the end result would (probably) be pretty fast and the code is straightforward, if repetitive.
Then I thought: hey, serde could be really good at automating the boring parts of this. Minus a few ugly details, this code follows a rigid structure and I could basically generate this code with a bit of glue.
I headed over to Writing a data format ยท Serde, copied the example, and started playing with it. But as clearly outlined in the text, this example is not based on a proper parser of any sort. My inclination was to just drag nom back in for that part, but I'm struggling to make the two talk to each other.
I'm wondering what people do in practical serde format backends? Is there a go-to parser library that people use? And would there happen to be any simple examples sitting around that would show me how to get started with that?
Thanks in advance.