File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change 11mod build_utils;
22use bindgen:: Builder ;
3- use std:: collections:: HashMap ;
43use std:: vec:: Vec ;
54
65
@@ -9,11 +8,9 @@ fn main() {
98
109 let borsh_derives: Vec < String > = vec ! [ "BorshSerialize" . to_string( ) , "BorshDeserialize" . to_string( ) ] ;
1110
12- let parser = build_utils:: DeriveAdderParserCallback { types_to_traits : HashMap :: from ( [
13- ( "cmd_hdr" , borsh_derives)
14- //map more struct names to traits here, be sure that the definitions of your traites
15- //are included in c_oracle_header.rs
16- ] ) } ;
11+ //make a parser and to it type, traits pairs
12+ let mut parser = build_utils:: DeriveAdderParserCallback :: new ( ) ;
13+ parser. register_traits ( "cmd_hdr" , borsh_derives) ;
1714
1815 //generate and write bindings
1916 let bindings = Builder :: default ( ) . header ( "./src/bindings.h" ) . parse_callbacks ( Box :: new ( parser) ) . rustfmt_bindings ( true ) . generate ( ) . expect ( "Unable to generate bindings" ) ;
Original file line number Diff line number Diff line change @@ -6,11 +6,23 @@ use std::collections::HashMap;
66///that the traits of each struct are added to its
77///definition when an instance of this struct
88///is provided as a ParseCallback for bindgen
9- #[ derive( Debug ) ]
9+ #[ derive( Debug , Default ) ]
1010pub struct DeriveAdderParserCallback < ' a > {
1111 pub types_to_traits : HashMap < & ' a str , Vec < String > > ,
1212}
1313
14+ impl < ' a > DeriveAdderParserCallback < ' a > {
15+ ///create a parser that does not add any traits
16+ pub fn new ( ) -> Self {
17+ Default :: default ( )
18+ }
19+ //add pairs of types and their desired traits
20+ pub fn register_traits ( & mut self , type_name : & ' a str , traits : Vec < String > ) {
21+ self . types_to_traits . insert ( & type_name, traits) ;
22+ }
23+
24+ }
25+
1426//this is required to implement the callback trait
1527impl UnwindSafe for DeriveAdderParserCallback < ' _ > { }
1628
You can’t perform that action at this time.
0 commit comments