3 ms·
Hi Josh! "Parse, don't validate" is one of my favourite programming blog posts of all time. Between Nom and Serde, I find it very easy to use that approach in R
by adamch 5y ago
Hi Josh! "Parse, don't validate" is one of my favourite programming blog posts of all time. Between Nom and Serde, I find it very easy to use that approach in Rust.
- imor80 5y agoYou mean "Parse, don't validate" right?
- adamch 5y agoOops, yes
- faitswulff 5y agoAs a beginner to both, when do you find yourself reaching for one instead of the other? Or do you use nom when deserializing with serde?
- adamch 5y agoSerde is good for self-describing formats like JSON, YAMK, TOML etc. At least that's what I use it for. Nom isn't necessary for them! Nom is good for protocols where you need to know the schema in advance. E.g. a binary key-value store, where the binary in the key and value has to be deserialised into some special rules. Nom can also handle bit-level parsers very easily. It's easier to use the parsers in nom::bits than remembering all the bit-shifting tricks I haven't used in five years. But I'm not an expert on Serde, I suspect it can do bit-level too. I've never written my own Serde library, I just use crates like serde-json.
- maleldil 5y agoI use Serde when it's a common format that already has implementations for Serialize/Deserialize, and nom/peg when it's a custom format.