@@ -85,6 +85,7 @@ use parse::{ClangItemParser, ParseError};
85
85
use regex_set:: RegexSet ;
86
86
87
87
use std:: borrow:: Cow ;
88
+ use std:: collections:: HashMap ;
88
89
use std:: fs:: { File , OpenOptions } ;
89
90
use std:: io:: { self , Write } ;
90
91
use std:: iter;
@@ -766,11 +767,25 @@ impl Builder {
766
767
767
768
/// Add a string to prepend to the generated bindings. The string is passed
768
769
/// through without any modification.
769
- pub fn raw_line < T : Into < String > > ( mut self , arg : T ) -> Builder {
770
+ pub fn raw_line < T : Into < String > > ( mut self , arg : T ) -> Self {
770
771
self . options . raw_lines . push ( arg. into ( ) ) ;
771
772
self
772
773
}
773
774
775
+ /// Add a given line to the beginning of module `mod`.
776
+ pub fn module_raw_line < T , U > ( mut self , mod_ : T , line : U ) -> Self
777
+ where
778
+ T : Into < String > ,
779
+ U : Into < String > ,
780
+ {
781
+ self . options
782
+ . module_lines
783
+ . entry ( mod_. into ( ) )
784
+ . or_insert_with ( Vec :: new)
785
+ . push ( line. into ( ) ) ;
786
+ self
787
+ }
788
+
774
789
/// Add an argument to be passed straight through to clang.
775
790
pub fn clang_arg < T : Into < String > > ( mut self , arg : T ) -> Builder {
776
791
self . options . clang_args . push ( arg. into ( ) ) ;
@@ -1300,9 +1315,15 @@ struct BindgenOptions {
1300
1315
/// Whether we should convert float types to f32/f64 types.
1301
1316
convert_floats : bool ,
1302
1317
1303
- /// The set of raw lines to prepend to the generated Rust code.
1318
+ /// The set of raw lines to prepend to the top-level module of generated
1319
+ /// Rust code.
1304
1320
raw_lines : Vec < String > ,
1305
1321
1322
+ /// The set of raw lines to prepend to each of the modules.
1323
+ ///
1324
+ /// This only makes sense if the `enable_cxx_namespaces` option is set.
1325
+ module_lines : HashMap < String , Vec < String > > ,
1326
+
1306
1327
/// The set of arguments to pass straight through to Clang.
1307
1328
clang_args : Vec < String > ,
1308
1329
@@ -1448,6 +1469,7 @@ impl Default for BindgenOptions {
1448
1469
msvc_mangling : false ,
1449
1470
convert_floats : true ,
1450
1471
raw_lines : vec ! [ ] ,
1472
+ module_lines : HashMap :: default ( ) ,
1451
1473
clang_args : vec ! [ ] ,
1452
1474
input_header : None ,
1453
1475
input_unsaved_files : vec ! [ ] ,
0 commit comments