Attributes

Attributes are used to customize the Serialize and Deserialize implementations produced by Serde's derive. They require a Rust compiler version 1.15 or newer.

There are three categories of attributes:

# #[macro_use]
# extern crate serde_derive;
#
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]  // <-- this is a container attribute
struct S {
    #[serde(default)]  // <-- this is a field attribute
    f: i32,
}

#[derive(Serialize, Deserialize)]
#[serde(rename = "e")]  // <-- this is also a container attribute
enum E {
    #[serde(rename = "a")]  // <-- this is a variant attribute
    A(String),
}
#
# fn main() {}

Note that a single struct, enum, variant, or field may have multiple attributes on it.