Skip to content

Commit 7129d89

Browse files
committed
lib: Add and document an API to add per-module raw lines.
1 parent af54e58 commit 7129d89

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/lib.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ use parse::{ClangItemParser, ParseError};
8585
use regex_set::RegexSet;
8686

8787
use std::borrow::Cow;
88+
use std::collections::HashMap;
8889
use std::fs::{File, OpenOptions};
8990
use std::io::{self, Write};
9091
use std::iter;
@@ -766,11 +767,25 @@ impl Builder {
766767

767768
/// Add a string to prepend to the generated bindings. The string is passed
768769
/// 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 {
770771
self.options.raw_lines.push(arg.into());
771772
self
772773
}
773774

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+
774789
/// Add an argument to be passed straight through to clang.
775790
pub fn clang_arg<T: Into<String>>(mut self, arg: T) -> Builder {
776791
self.options.clang_args.push(arg.into());
@@ -1300,9 +1315,15 @@ struct BindgenOptions {
13001315
/// Whether we should convert float types to f32/f64 types.
13011316
convert_floats: bool,
13021317

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.
13041320
raw_lines: Vec<String>,
13051321

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+
13061327
/// The set of arguments to pass straight through to Clang.
13071328
clang_args: Vec<String>,
13081329

@@ -1448,6 +1469,7 @@ impl Default for BindgenOptions {
14481469
msvc_mangling: false,
14491470
convert_floats: true,
14501471
raw_lines: vec![],
1472+
module_lines: HashMap::default(),
14511473
clang_args: vec![],
14521474
input_header: None,
14531475
input_unsaved_files: vec![],

0 commit comments

Comments
 (0)