@@ -25,8 +25,8 @@ impl Default for MacroParsingBehavior {
25
25
26
26
/// A trait to allow configuring different kinds of types in different
27
27
/// situations.
28
- pub trait ParseCallbacks :
29
- fmt:: Debug + UnwindSafe + dyn_clone :: DynClone
28
+ # [ cfg ( not ( feature = "builder-clone" ) ) ]
29
+ pub trait ParseCallbacks : fmt:: Debug + UnwindSafe
30
30
{
31
31
/// This function will be run on every macro that is identified.
32
32
fn will_parse_macro ( & self , _name : & str ) -> MacroParsingBehavior {
@@ -107,4 +107,90 @@ pub trait ParseCallbacks:
107
107
}
108
108
}
109
109
110
+ /// The same trait as above, but clonable so that it can be included as a
111
+ /// field in Builder when the builder-clone feature is enabled such that
112
+ /// Builder implements Clone.
113
+ #[ cfg( feature = "builder-clone" ) ]
114
+ pub trait ParseCallbacks : fmt:: Debug + UnwindSafe + dyn_clone:: DynClone
115
+ {
116
+ /// This function will be run on every macro that is identified.
117
+ fn will_parse_macro ( & self , _name : & str ) -> MacroParsingBehavior {
118
+ MacroParsingBehavior :: Default
119
+ }
120
+
121
+ /// The integer kind an integer macro should have, given a name and the
122
+ /// value of that macro, or `None` if you want the default to be chosen.
123
+ fn int_macro ( & self , _name : & str , _value : i64 ) -> Option < IntKind > {
124
+ None
125
+ }
126
+
127
+ /// This will be run on every string macro. The callback cannot influence the further
128
+ /// treatment of the macro, but may use the value to generate additional code or configuration.
129
+ fn str_macro ( & self , _name : & str , _value : & [ u8 ] ) { }
130
+
131
+ /// This will be run on every function-like macro. The callback cannot
132
+ /// influence the further treatment of the macro, but may use the value to
133
+ /// generate additional code or configuration.
134
+ ///
135
+ /// The first parameter represents the name and argument list (including the
136
+ /// parentheses) of the function-like macro. The second parameter represents
137
+ /// the expansion of the macro as a sequence of tokens.
138
+ fn func_macro ( & self , _name : & str , _value : & [ & [ u8 ] ] ) { }
139
+
140
+ /// This function should return whether, given an enum variant
141
+ /// name, and value, this enum variant will forcibly be a constant.
142
+ fn enum_variant_behavior (
143
+ & self ,
144
+ _enum_name : Option < & str > ,
145
+ _original_variant_name : & str ,
146
+ _variant_value : EnumVariantValue ,
147
+ ) -> Option < EnumVariantCustomBehavior > {
148
+ None
149
+ }
150
+
151
+ /// Allows to rename an enum variant, replacing `_original_variant_name`.
152
+ fn enum_variant_name (
153
+ & self ,
154
+ _enum_name : Option < & str > ,
155
+ _original_variant_name : & str ,
156
+ _variant_value : EnumVariantValue ,
157
+ ) -> Option < String > {
158
+ None
159
+ }
160
+
161
+ /// Allows to rename an item, replacing `_original_item_name`.
162
+ fn item_name ( & self , _original_item_name : & str ) -> Option < String > {
163
+ None
164
+ }
165
+
166
+ /// This will be called on every file inclusion, with the full path of the included file.
167
+ fn include_file ( & self , _filename : & str ) { }
168
+
169
+ /// This will be called to determine whether a particular blocklisted type
170
+ /// implements a trait or not. This will be used to implement traits on
171
+ /// other types containing the blocklisted type.
172
+ ///
173
+ /// * `None`: use the default behavior
174
+ /// * `Some(ImplementsTrait::Yes)`: `_name` implements `_derive_trait`
175
+ /// * `Some(ImplementsTrait::Manually)`: any type including `_name` can't
176
+ /// derive `_derive_trait` but can implemented it manually
177
+ /// * `Some(ImplementsTrait::No)`: `_name` doesn't implement `_derive_trait`
178
+ fn blocklisted_type_implements_trait (
179
+ & self ,
180
+ _name : & str ,
181
+ _derive_trait : DeriveTrait ,
182
+ ) -> Option < ImplementsTrait > {
183
+ None
184
+ }
185
+
186
+ /// Provide a list of custom derive attributes.
187
+ ///
188
+ /// If no additional attributes are wanted, this function should return an
189
+ /// empty `Vec`.
190
+ fn add_derives ( & self , _name : & str ) -> Vec < String > {
191
+ vec ! [ ]
192
+ }
193
+ }
194
+
195
+ #[ cfg( feature = "builder-clone" ) ]
110
196
dyn_clone:: clone_trait_object!( ParseCallbacks ) ;
0 commit comments