#[derive(DeserializeShape)]
{
// Attributes available to this derive:
#[serde]
#[serde_shape]
}
Available on crate feature
derive only.Expand description
Derives DeserializeShape from Serde deserialization metadata.
Use this macro when a type’s accepted input shape should be reflected from the same metadata that Serde uses for deserialization. The generated implementation records the deserialization-side names, shape graph, and Serde field/container metadata.
Use #[serde_shape(deserialize_with = "path")] on a container, variant, or field to
override an opaque or foreign representation. The function must accept &mut DeserializeShapeContext and return a ShapeRef. Generic hooks can replace inferred
bounds with #[serde_shape(bound(deserialize = "T: DeserializeShape"))] on the container.
§Example
use serde_shape::DefaultShape;
use serde_shape::DeserializeDefinitionKind;
use serde_shape::DeserializeShape;
#[derive(DeserializeShape)]
#[serde(rename_all = "kebab-case")]
struct Config {
listen_addr: String,
#[serde(default)]
worker_count: u16,
}
let graph = Config::deserialize_shape();
let definition = graph.root_definition().unwrap();
let DeserializeDefinitionKind::Struct(shape) = &definition.kind else {
panic!("Config should produce a struct shape");
};
assert_eq!(shape.fields[0].name, "listen-addr");
assert_eq!(shape.fields[1].name, "worker-count");
assert_eq!(shape.fields[1].default, DefaultShape::Default);Derives serde_shape::DeserializeShape from Serde deserialization metadata.