diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-05-03 04:21:08 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-05-03 04:21:08 +0200 |
commit | 7129d896a218a035c177930c11b954734f9f180c (patch) | |
tree | e3ce1074b1752e5bc271d16da8356c87a4276db4 /src | |
parent | af54e58a8c2e513ba8c3cc00c22aa958de091a53 (diff) |
lib: Add and document an API to add per-module raw lines.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -85,6 +85,7 @@ use parse::{ClangItemParser, ParseError}; use regex_set::RegexSet; use std::borrow::Cow; +use std::collections::HashMap; use std::fs::{File, OpenOptions}; use std::io::{self, Write}; use std::iter; @@ -766,11 +767,25 @@ impl Builder { /// Add a string to prepend to the generated bindings. The string is passed /// through without any modification. - pub fn raw_line<T: Into<String>>(mut self, arg: T) -> Builder { + pub fn raw_line<T: Into<String>>(mut self, arg: T) -> Self { self.options.raw_lines.push(arg.into()); self } + /// Add a given line to the beginning of module `mod`. + pub fn module_raw_line<T, U>(mut self, mod_: T, line: U) -> Self + where + T: Into<String>, + U: Into<String>, + { + self.options + .module_lines + .entry(mod_.into()) + .or_insert_with(Vec::new) + .push(line.into()); + self + } + /// Add an argument to be passed straight through to clang. pub fn clang_arg<T: Into<String>>(mut self, arg: T) -> Builder { self.options.clang_args.push(arg.into()); @@ -1300,9 +1315,15 @@ struct BindgenOptions { /// Whether we should convert float types to f32/f64 types. convert_floats: bool, - /// The set of raw lines to prepend to the generated Rust code. + /// The set of raw lines to prepend to the top-level module of generated + /// Rust code. raw_lines: Vec<String>, + /// The set of raw lines to prepend to each of the modules. + /// + /// This only makes sense if the `enable_cxx_namespaces` option is set. + module_lines: HashMap<String, Vec<String>>, + /// The set of arguments to pass straight through to Clang. clang_args: Vec<String>, @@ -1448,6 +1469,7 @@ impl Default for BindgenOptions { msvc_mangling: false, convert_floats: true, raw_lines: vec![], + module_lines: HashMap::default(), clang_args: vec![], input_header: None, input_unsaved_files: vec![], |