-
Using derive · Serde
Serialize and
Deserialize traits for data structures defined in your crate, allowing them to
be represented conveniently in all of Serde's data formats.
You only need to set this up if your code is u...
-
Examples · Serde
serde_json for structs and enums. Other
human-readable data formats are encouraged to follow an analogous approach where
possible.
Enum representations: Externally tagged,
internally tagged, adjacentl...
-
Field attributes · Serde
#[serde(rename = "name")]
Serialize and deserialize this field with the given name instead of its Rust
name. This is useful for serializing fields as camelCase or
serializing fields with names that ar...
-
Custom serialization · Serde
The traits each have a single method:
pub trait Serialize {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer;
}
pub trait Deserialize<'de>: Sized {...
-
Implementing Deserialize · Serde
Deserialize impl and passed to a
Deserializer. The
Visitor in order
to construct the desired type.
Here is a
i32 from a variety
of types.
use std::fmt;
use serde::de::{self, Visitor};
struct I32V...
-
Serde data model · Serde
Serde data model
The Serde data model is the API by which data structures and data formats
interact. You can think of it as Serde's type system.
In code, the serialization half of the Serde data model...