programming-language-rust-serde.html
* created: 2026-01-16T10:39
* modified: 2026-01-19T09:44
title
Rust Ecosystem: Serde
description
A crate used to serialize and deserialize.
Rust Ecosystem: Serde
The overall structure of Serde consists of:
- data type: The rust type in use (
Serialize and Deserialize).
- data model: Mapping types to a giving format and vise versa.
- data format: A data format like JSON (
Serializer and Deserializer).
The Data Model
A simplified form of the Rust type system; it contains primitives like bool, u8, u16, .. and char, but also string, byte array, option, unit and so on.
The requirements for any Rust data type is to implement Serialize to describe how to emit their data, and
Deserialize to describe how to construct themselves from incoming data.
On the other side, the Serializer is responsible for converting the Serde data model to the bytes of the serialize protocol (e.g. JSON). The Deserializer maps the data of any given protocol to the Serde data model. When the Deserializer encounters a bool for example, it will call the visit-bool method, which will end up calling the corresponding deserialize method on our Rust data type.
The Serde data model is therefore not a intermediate Serde data model type which both sides can convert into, but more like a map, telling the implementation of a data format which methods to call to construct your Rust data type (and also the other way around). The benefit being that we don't have to allocate memory for our in-between type, instead constructing our desired type directly.
That data is not converted into a intermediate Serde data model type, it expresses itself in terms of the Serde data model.