In a parsed derive-macro input, `ast.data` holds the declaration's data shape. `syn::Data` is an enum with `Struct`, `Enum`, and `Union` variants, letting macro code branch on the target kind. section 4.4
pub enum Data {
Struct(DataStruct), #1
Enum(DataEnum),
Union(DataUnion),
}
Inspect the three `syn::Data` variants and their nested types. section 4.4
Extracting named struct fields
Match the `Struct` variant, descend through `DataStruct` and `FieldsNamed`, and reject other shapes when the macro only supports named-field structs: `let fields = match ast.data { Struct(DataStruct { fields: Named(FieldsNamed { ref named, .. }), .. }) => named, _ => unimplemented!("only works for structs with named fields"), };` The resulting fields can then be iterated to generate public declarations. section 4.4
