Sitemap
Jesse L

Jesse L

Hi, I'm a passionate technology enthusiast and lifelong learner. Beyond my technical pursuits, I'm also passionate about sharing my enthusiasm with others.

Member-only story

Serde: Code Generation You Can Read

10 min read4 days ago

Hi everyone, welcome back. Today, I will be going over Serde — the serialization framework most of the Rust ecosystem is built on, and this article covers what it is, how its data model and derive macro work, how to install it, and how to use it.

One idea sits at the centre of Serde and explains nearly everything else. Most languages serialize with runtime reflection: a library inspects your object while the program runs and emits its fields. Rust has no reflection, so Serde generates the code at compile time instead. Everything good and bad about Serde follows from that choice. You get serialization the compiler type-checks, no runtime schema lookup, and formats that work with types their authors never saw; you pay in compile time, binary size and generic errors.

Press enter or click to view image in full size
Photo by Daniil Komov on Unsplash

The Vocabulary, First

If you are newer to this, here is the glossary the rest of this article leans on.

Serialization is turning a value in your program’s memory into a flat sequence of bytes or text you can store or send. Deserialization is the reverse, rebuilding the value from those bytes.

A wire format is the agreed shape of those bytes. JSON, YAML, TOML, MessagePack, CBOR and bincode all qualify. Some are text, some binary, and they disagree about which types exist at all — the problem Serde manages.

--

--

Jesse L
Jesse L

Written by Jesse L

Hi, I'm a passionate technology enthusiast and lifelong learner. Beyond my technical pursuits, I'm also passionate about sharing my enthusiasm with others.