@@ -225,6 +225,24 @@ where
225
225
"Create PartialEq implementation, if it can not be derived \
226
226
automatically.",
227
227
) ,
228
+ Arg :: new ( "with-derive-custom" )
229
+ . long ( "with-derive-custom" )
230
+ . help (
231
+ "Derive custom traits on any type. \
232
+ Don't use with --with-derive-custom-struct.",
233
+ )
234
+ . value_name ( "trait" )
235
+ . multiple_occurrences ( true )
236
+ . number_of_values ( 1 ) ,
237
+ Arg :: new ( "with-derive-custom-struct" )
238
+ . long ( "with-derive-custom-struct" )
239
+ . help (
240
+ "Derive custom traits on any struct.\
241
+ Don't use with --with-derive-custom.",
242
+ )
243
+ . value_name ( "trait" )
244
+ . multiple_occurrences ( true )
245
+ . number_of_values ( 1 ) ,
228
246
Arg :: new ( "with-derive-default" )
229
247
. long ( "with-derive-default" )
230
248
. help ( "Derive Default on any type." ) ,
@@ -744,6 +762,36 @@ where
744
762
builder = builder. impl_partialeq ( true ) ;
745
763
}
746
764
765
+ if let Some ( traits) = matches. values_of ( "with-derive-custom" ) {
766
+ #[ derive( Debug ) ]
767
+ struct CustomTraitCallback {
768
+ derives : Vec < String >
769
+ }
770
+ impl bindgen:: callbacks:: ParseCallbacks for CustomTraitCallback {
771
+ fn add_derives ( & self , _name : & str ) -> Vec < String > {
772
+ self . derives . to_owned ( )
773
+ }
774
+ }
775
+
776
+ let derives: Vec < String > = traits. into_iter ( ) . map ( |t| t. to_string ( ) ) . collect ( ) ;
777
+ builder = builder. parse_callbacks ( Box :: new ( CustomTraitCallback { derives } ) ) ;
778
+ }
779
+
780
+ if let Some ( traits) = matches. values_of ( "with-derive-custom-struct" ) {
781
+ #[ derive( Debug ) ]
782
+ struct CustomTraitCallback {
783
+ derives : Vec < String >
784
+ }
785
+ impl bindgen:: callbacks:: ParseCallbacks for CustomTraitCallback {
786
+ fn add_derives_struct ( & self , _name : & str ) -> Vec < String > {
787
+ self . derives . to_owned ( )
788
+ }
789
+ }
790
+
791
+ let derives: Vec < String > = traits. into_iter ( ) . map ( |t| t. to_string ( ) ) . collect ( ) ;
792
+ builder = builder. parse_callbacks ( Box :: new ( CustomTraitCallback { derives } ) ) ;
793
+ }
794
+
747
795
if matches. is_present ( "with-derive-default" ) {
748
796
builder = builder. derive_default ( true ) ;
749
797
}
0 commit comments