1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use TokenStream;
use crateVariantsDataStructAttrMeta;
use crate;
use crateVariantsDataStructMeta;
/// Derive macro to generate a data struct containing fields for each variant of the enum.
///
/// ```rust
/// use variants_data_struct::VariantsDataStruct;
///
/// #[derive(VariantsDataStruct)]
/// pub enum MyEnum {
/// UnitEnum,
/// TupleEnum(i32, String),
/// StructEnum { id: u32, name: String },
/// }
///
/// // Equivalent to:
/// // pub struct MyEnumVariantsData {
/// // pub unit_enum: (),
/// // pub tuple_enum: TupleEnumVariantType,
/// // pub struct_enum: StructEnumVariantType,
/// // }
/// //
/// // pub struct TupleEnumVariantType(pub i32, pub String);
/// //
/// // pub struct StructEnumVariantType {
/// // pub id: u32,
/// // pub name: String,
/// // }
/// ```
///
/// ## Helper attributes
///
/// ### `#[variants_data_struct(<meta>)]` customizes the behavior of the derive macro.
///
/// The `<meta>` (see [`VariantsDataStructAttrMeta`](crate::variants_data_struct_attr_meta::VariantsDataStructAttrMeta))
/// is a comma-separated list that can contain the following items:
///
// - `attrs(#[derive(...)] ...)`: Adds the specified attributes to the generated data struct. Notably, you
/// can use it to add derives like `Debug`, `Clone` to the generated struct.
/// - `vis = <visibility>`: Specifies a custom visibility for the generated data struct. If not provided,
/// the visibility of the original enum is used.
/// - `name = <CustomName>`: Specifies a custom name for the generated data struct.
/// If not provided, the default name is `<EnumName>VariantsData`.
/// - `variants_tys_attrs(#[derive(...)] ...)`: Adds the specified attributes to each of the generated variant type structs.
/// Notably, you can use it to add derives like `Debug`, `Clone` to the generated variant type structs.
///
/// ### `#[variants_data_struct_field(<meta>)]` customizes the behavior of individual fields in the generated data struct
/// and their corresponding variant types.
///
/// The `<meta>` (see [`VariantsDataStructFieldAttrMeta`](crate::variants_data_struct_field_attr_meta::VariantsDataStructFieldAttrMeta))
/// is a comma-separated list that can contain the following items:
///
/// - `field_attrs(#[derive(...)] ...)`: Adds the specified attributes to the generated field in the data struct.
/// Notably, you can use it to add derives like `Debug`, `Clone` to
/// the generated field.
/// - `field_vis = <visibility>`: Specifies a custom visibility for the generated field in the data struct. If not provided,
/// the visibility of the generated data struct is used.
/// - `field_name = <custom_field_name>`: Specifies a custom name for the generated field in the data struct. If not provided,
/// the name is derived from the original variant's name (converted to `snake_case`).
/// - `field_ty_override`: Overrides the type of the generated field in the data struct. If not provided,
/// the type is derived from the original variant's fields. For variants without fields (a unit variant or a struct or tuple variant with no fields),
/// the type is `()`. For tuple and struct variants, a separate "variant type" struct is generated to encapsulate the fields.
/// - `gen_variant_ty`: Overrides the decision whether to generate a separate "variant type" struct for the variant.
/// If not provided, a "variant type" struct is generated for tuple and struct variants, and not for unit variants. If `field_ty_override` is provided,
/// by default, no "variant type" struct is generated.