[−][src]Crate serde
Serde
Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.
The Serde ecosystem consists of data structures that know how to serialize and deserialize themselves along with data formats that know how to serialize and deserialize other things. Serde provides the layer by which these two groups interact with each other, allowing any supported data structure to be serialized and deserialized using any supported data format.
See the Serde website https://serde.rs/ for additional documentation and usage examples.
Design
Where many other languages rely on runtime reflection for serializing data,
Serde is instead built on Rust's powerful trait system. A data structure
that knows how to serialize and deserialize itself is one that implements
Serde's Serialize
and Deserialize
traits (or uses Serde's derive
attribute to automatically generate implementations at compile time). This
avoids any overhead of reflection or runtime type information. In fact in
many situations the interaction between data structure and data format can
be completely optimized away by the Rust compiler, leaving Serde
serialization to perform the same speed as a handwritten serializer for the
specific selection of data structure and data format.
Data formats
The following is a partial list of data formats that have been implemented for Serde by the community.
- JSON, the ubiquitous JavaScript Object Notation used by many HTTP APIs.
- Bincode, a compact binary format used for IPC within the Servo rendering engine.
- CBOR, a Concise Binary Object Representation designed for small message size without the need for version negotiation.
- YAML, a popular human-friendly configuration language that ain't markup language.
- MessagePack, an efficient binary format that resembles a compact JSON.
- TOML, a minimal configuration format used by Cargo.
- Pickle, a format common in the Python world.
- RON, a Rusty Object Notation.
- BSON, the data storage and network transfer format used by MongoDB.
- Avro, a binary format used within Apache Hadoop, with support for schema definition.
- JSON5, A superset of JSON including some productions from ES5.
- URL, the x-www-form-urlencoded format.
- Envy, a way to deserialize environment variables into Rust structs. (deserialization only)
- Envy Store, a way to deserialize AWS Parameter Store parameters into Rust structs. (deserialization only)
- Postcard, a
no_std
and embedded-systems friendly compact binary format.
Modules
de | Generic data structure deserialization framework. |
ser | Generic data structure serialization framework. |
Macros
forward_to_deserialize_any | Helper macro when implementing the |
serde_if_integer128 | Conditional compilation depending on whether Serde is built with support for 128-bit integers. |
Traits
Deserialize | A data structure that can be deserialized from any data format supported by Serde. |
Deserializer | A data format that can deserialize any data structure supported by Serde. |
Serialize | A data structure that can be serialized into any data format supported by Serde. |
Serializer | A data format that can serialize any data structure supported by Serde. |