@@ -25,8 +25,93 @@ impl Default for MacroParsingBehavior {
25
25
26
26
/// A trait to allow configuring different kinds of types in different
27
27
/// situations.
28
+ #[ cfg( not( feature = "builder-clone" ) ) ]
29
+ pub trait ParseCallbacks : fmt:: Debug + UnwindSafe {
30
+ /// This function will be run on every macro that is identified.
31
+ fn will_parse_macro ( & self , _name : & str ) -> MacroParsingBehavior {
32
+ MacroParsingBehavior :: Default
33
+ }
34
+
35
+ /// The integer kind an integer macro should have, given a name and the
36
+ /// value of that macro, or `None` if you want the default to be chosen.
37
+ fn int_macro ( & self , _name : & str , _value : i64 ) -> Option < IntKind > {
38
+ None
39
+ }
40
+
41
+ /// This will be run on every string macro. The callback cannot influence the further
42
+ /// treatment of the macro, but may use the value to generate additional code or configuration.
43
+ fn str_macro ( & self , _name : & str , _value : & [ u8 ] ) { }
44
+
45
+ /// This will be run on every function-like macro. The callback cannot
46
+ /// influence the further treatment of the macro, but may use the value to
47
+ /// generate additional code or configuration.
48
+ ///
49
+ /// The first parameter represents the name and argument list (including the
50
+ /// parentheses) of the function-like macro. The second parameter represents
51
+ /// the expansion of the macro as a sequence of tokens.
52
+ fn func_macro ( & self , _name : & str , _value : & [ & [ u8 ] ] ) { }
53
+
54
+ /// This function should return whether, given an enum variant
55
+ /// name, and value, this enum variant will forcibly be a constant.
56
+ fn enum_variant_behavior (
57
+ & self ,
58
+ _enum_name : Option < & str > ,
59
+ _original_variant_name : & str ,
60
+ _variant_value : EnumVariantValue ,
61
+ ) -> Option < EnumVariantCustomBehavior > {
62
+ None
63
+ }
64
+
65
+ /// Allows to rename an enum variant, replacing `_original_variant_name`.
66
+ fn enum_variant_name (
67
+ & self ,
68
+ _enum_name : Option < & str > ,
69
+ _original_variant_name : & str ,
70
+ _variant_value : EnumVariantValue ,
71
+ ) -> Option < String > {
72
+ None
73
+ }
74
+
75
+ /// Allows to rename an item, replacing `_original_item_name`.
76
+ fn item_name ( & self , _original_item_name : & str ) -> Option < String > {
77
+ None
78
+ }
79
+
80
+ /// This will be called on every file inclusion, with the full path of the included file.
81
+ fn include_file ( & self , _filename : & str ) { }
82
+
83
+ /// This will be called to determine whether a particular blocklisted type
84
+ /// implements a trait or not. This will be used to implement traits on
85
+ /// other types containing the blocklisted type.
86
+ ///
87
+ /// * `None`: use the default behavior
88
+ /// * `Some(ImplementsTrait::Yes)`: `_name` implements `_derive_trait`
89
+ /// * `Some(ImplementsTrait::Manually)`: any type including `_name` can't
90
+ /// derive `_derive_trait` but can implemented it manually
91
+ /// * `Some(ImplementsTrait::No)`: `_name` doesn't implement `_derive_trait`
92
+ fn blocklisted_type_implements_trait (
93
+ & self ,
94
+ _name : & str ,
95
+ _derive_trait : DeriveTrait ,
96
+ ) -> Option < ImplementsTrait > {
97
+ None
98
+ }
99
+
100
+ /// Provide a list of custom derive attributes.
101
+ ///
102
+ /// If no additional attributes are wanted, this function should return an
103
+ /// empty `Vec`.
104
+ fn add_derives ( & self , _name : & str ) -> Vec < String > {
105
+ vec ! [ ]
106
+ }
107
+ }
108
+
109
+ /// The same trait as above, but clonable so that it can be included as a
110
+ /// field in Builder when the builder-clone feature is enabled such that
111
+ /// Builder implements Clone.
112
+ #[ cfg( feature = "builder-clone" ) ]
28
113
pub trait ParseCallbacks :
29
- fmt:: Debug + UnwindSafe + dyn_clone:: DynClone
114
+ fmt:: Debug + UnwindSafe + dyn_clone:: DynClone
30
115
{
31
116
/// This function will be run on every macro that is identified.
32
117
fn will_parse_macro ( & self , _name : & str ) -> MacroParsingBehavior {
@@ -107,4 +192,5 @@ pub trait ParseCallbacks:
107
192
}
108
193
}
109
194
195
+ #[ cfg( feature = "builder-clone" ) ]
110
196
dyn_clone:: clone_trait_object!( ParseCallbacks ) ;
0 commit comments