
Understanding Serde - JoshMcguigan
https://www.joshmcguigan.com/blog/understanding-serde/
======
bestouff
Serde is one of Rust's killer feature which makes you appreciate the
philosophy behind the language. With just a few annotations you have a robust
and complete parser for whatever format (JSON, TOML, etc.) automatically built
for serializing and deserializing your data structures. And it's fast, and
optionnally zero-copy. I've never seen this in other languages.

~~~
jimenezrick
Haskell? Data generics isn't really nothing new. We had this technology for
years.

~~~
earthboundkid
Haskell has been around for more than a decade and had huge uptake by language
nerds, but the only significant OSS written in it is Pandoc. In contrast, Rust
already has Servo and a number of CLI tools, ripgrep being the most prominent.

~~~
leshow
I'm not sure what you consider 'significant', but to my mind, there are many
great haskell open source projects: xmonad, shellcheck, stack, haxl, to name a
few.

Not to mention how many languages are written in it: Elm, Purescript, Idris,
GHC itself.

~~~
earthboundkid
I almost listed xmonad. I haven’t heard of the other ones. Doesn’t change my
point.

------
kolektiv
Serde is very strong indeed (although not the easiest to understand, this
would have been useful when I implemented a Serde library for [de]serialising
with the AWS DynamoDB AttributeValue format).

That said, I've always had a slight problem with this approach to
serialisation in general, which is that it makes it very hard to have multiple
serialisation approaches for a single type (e.g. I want one casing rule for
one target, and a different one for another). This seems effectively
impossible with an approach based on annotations/macros. Would love to know
how others have dealt with that.

~~~
JoshMcguigan
> I want one casing rule for one target, and a different one for another

Hmm, this is interesting, and something I hadn't thought of before. I'd
probably try to solve it with a combination of the newtype pattern (create
wrapper types for `MyThing`, like `MyThingJson` and `MyThingToml`) and the
Serde flatten attribute. Then you could, for example, add `#[serde(rename_all
= "lowercase")]` to the `MyThingJson` struct and `#[serde(rename_all =
"snake_case")]` to the `MyThingToml` struct.

I haven't tested this though, so I'm not sure if the `rename_all` would flow
through the flatten attribute as expected. Worst case you could duplicate the
struct (or more likely, find or build a macro to do it for you) rather than
use the newtype/flatten technique.

------
lmkg
Pronunciation question: Does Serde have one syllable or two? Looking at the
word out of context, it seems the e at the end ought to be silent. But it's
derived as an abbreviation from SERialize/DEserialize. Does the author or
community have a consensus on one of these being the "correct" form?

~~~
erickt
Original author of serde here. I call it sir-dee, but the current maintainer,
dtolnay, calls it sear-day. But we really don't care how people pronounce it.
It's really more of a neither / potato thing:

[https://www.youtube.com/watch?v=K75g7eRhH9M](https://www.youtube.com/watch?v=K75g7eRhH9M)

~~~
mercer
Just wanted to thank you for the great work. Thanks!

------
eggie5
I recently saw this strange word Serde in some Hive table create commands...

~~~
dfsegoat
[https://cwiki.apache.org/confluence/display/Hive/SerDe](https://cwiki.apache.org/confluence/display/Hive/SerDe)

This was where I first saw it as well. Years ago...

