From 7129d896a218a035c177930c11b954734f9f180c Mon Sep 17 00:00:00 2001 From: Emilio Cobos Álvarez Date: Thu, 3 May 2018 04:21:08 +0200 Subject: lib: Add and document an API to add per-module raw lines. --- src/lib.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c715b9c2..9073800f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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>(mut self, arg: T) -> Builder { + pub fn raw_line>(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(mut self, mod_: T, line: U) -> Self + where + T: Into, + U: Into, + { + 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>(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, + /// 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>, + /// The set of arguments to pass straight through to Clang. clang_args: Vec, @@ -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![], -- cgit v1.2.3