pub struct Builder { /* private fields */ }
Expand description
Configure and generate Rust bindings for a C/C++ header.
This is the main entry point to the library.
use bindgen::builder;
// Configure and generate bindings.
let bindings = builder().header("path/to/input/header")
.allowlist_type("SomeCoolClass")
.allowlist_function("do_some_cool_thing")
.generate()?;
// Write the generated bindings to an output file.
bindings.write_to_file("path/to/output.rs")?;
§Enums
Bindgen can map C/C++ enums into Rust in different ways. The way bindgen maps enums depends on the pattern passed to several methods:
For each C enum, bindgen tries to match the pattern in the following order:
- Constified enum module
- Bitfield enum
- Newtype enum
- Rustified enum
If none of the above patterns match, then bindgen will generate a set of Rust constants.
§Clang arguments
Extra arguments can be passed to with clang:
clang_arg()
: takes a single argumentclang_args()
: takes an iterator of argumentsBINDGEN_EXTRA_CLANG_ARGS
environment variable: whitespace separate environment variable of arguments
Clang arguments specific to your crate should be added via the
clang_arg()
/clang_args()
methods.
End-users of the crate may need to set the BINDGEN_EXTRA_CLANG_ARGS
environment variable to
add additional arguments. For example, to build against a different sysroot a user could set
BINDGEN_EXTRA_CLANG_ARGS
to --sysroot=/path/to/sysroot
.
§Regular expression arguments
Some Builder
methods like the allowlist_*
and blocklist_*
family of methods allow
regular expressions as arguments. These regular expressions will be parenthesized and wrapped
in ^
and $
. So if <regex>
is passed as argument, the regular expression to be stored will
be ^(<regex>)$
.
Implementations§
source§impl Builder
impl Builder
sourcepub fn command_line_flags(&self) -> Vec<String>
pub fn command_line_flags(&self) -> Vec<String>
Generates the command line flags use for creating Builder
.
sourcepub fn header<T: Into<String>>(self, header: T) -> Builder
pub fn header<T: Into<String>>(self, header: T) -> Builder
Add an input C/C++ header to generate bindings for.
This can be used to generate bindings to a single header:
let bindings = bindgen::Builder::default()
.header("input.h")
.generate()
.unwrap();
Or you can invoke it multiple times to generate bindings to multiple headers:
let bindings = bindgen::Builder::default()
.header("first.h")
.header("second.h")
.header("third.h")
.generate()
.unwrap();
sourcepub fn depfile<H: Into<String>, D: Into<PathBuf>>(
self,
output_module: H,
depfile: D,
) -> Builder
pub fn depfile<H: Into<String>, D: Into<PathBuf>>( self, output_module: H, depfile: D, ) -> Builder
Add a depfile output which will be written alongside the generated bindings.
sourcepub fn header_contents(self, name: &str, contents: &str) -> Builder
pub fn header_contents(self, name: &str, contents: &str) -> Builder
Add contents
as an input C/C++ header named name
.
The file name
will be added to the clang arguments.
sourcepub fn rust_target(self, rust_target: RustTarget) -> Self
pub fn rust_target(self, rust_target: RustTarget) -> Self
Specify the rust target
The default is the latest stable Rust version
sourcepub fn disable_untagged_union(self) -> Self
pub fn disable_untagged_union(self) -> Self
Disable support for native Rust unions, if supported.
sourcepub fn disable_header_comment(self) -> Self
pub fn disable_header_comment(self) -> Self
Disable insertion of bindgen’s version identifier into generated bindings.
sourcepub fn emit_ir_graphviz<T: Into<String>>(self, path: T) -> Builder
pub fn emit_ir_graphviz<T: Into<String>>(self, path: T) -> Builder
Set the output graphviz file.
sourcepub fn generate_comments(self, doit: bool) -> Self
pub fn generate_comments(self, doit: bool) -> Self
Whether the generated bindings should contain documentation comments (docstrings) or not. This is set to true by default.
Note that clang by default excludes comments from system headers, pass
-fretain-comments-from-system-headers
as
clang_arg
to include them. It can also be told
to process all comments (not just documentation ones) using the
-fparse-all-comments
flag. See slides on clang comment parsing for
background and examples.
sourcepub fn allowlist_recursively(self, doit: bool) -> Self
pub fn allowlist_recursively(self, doit: bool) -> Self
Whether to allowlist recursively or not. Defaults to true.
Given that we have explicitly allowlisted the “initiate_dance_party” function in this C header:
typedef struct MoonBoots {
int bouncy_level;
} MoonBoots;
void initiate_dance_party(MoonBoots* boots);
We would normally generate bindings to both the initiate_dance_party
function and the MoonBoots
struct that it transitively references. By
configuring with allowlist_recursively(false)
, bindgen
will not emit
bindings for anything except the explicitly allowlisted items, and there
would be no emitted struct definition for MoonBoots
. However, the
initiate_dance_party
function would still reference MoonBoots
!
Disabling this feature will almost certainly cause bindgen
to emit
bindings that will not compile! If you disable this feature, then it
is your responsibility to provide definitions for every type that is
referenced from an explicitly allowlisted item. One way to provide the
definitions is by using the Builder::raw_line
method, another would be to define them in Rust and then include!(...)
the bindings immediately afterwards.
sourcepub fn objc_extern_crate(self, doit: bool) -> Self
pub fn objc_extern_crate(self, doit: bool) -> Self
Generate #[macro_use] extern crate objc;
instead of use objc;
in the prologue of the files generated from objective-c files
sourcepub fn generate_block(self, doit: bool) -> Self
pub fn generate_block(self, doit: bool) -> Self
Generate proper block signatures instead of void pointers.
sourcepub fn block_extern_crate(self, doit: bool) -> Self
pub fn block_extern_crate(self, doit: bool) -> Self
Generate #[macro_use] extern crate block;
instead of use block;
in the prologue of the files generated from apple block files
sourcepub fn trust_clang_mangling(self, doit: bool) -> Self
pub fn trust_clang_mangling(self, doit: bool) -> Self
Whether to use the clang-provided name mangling. This is true by default and probably needed for C++ features.
However, some old libclang versions seem to return incorrect results in some cases for non-mangled functions, see 1, so we allow disabling it.
sourcepub fn blocklist_type<T: AsRef<str>>(self, arg: T) -> Builder
pub fn blocklist_type<T: AsRef<str>>(self, arg: T) -> Builder
Hide the given type from the generated bindings. Regular expressions are supported.
To blocklist types prefixed with “mylib” use "mylib_.*"
.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn blocklist_function<T: AsRef<str>>(self, arg: T) -> Builder
pub fn blocklist_function<T: AsRef<str>>(self, arg: T) -> Builder
Hide the given function from the generated bindings. Regular expressions are supported.
Methods can be blocklisted by prefixing the name of the type implementing
them followed by an underscore. So if Foo
has a method bar
, it can
be blocklisted as Foo_bar
.
To blocklist functions prefixed with “mylib” use "mylib_.*"
.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn blocklist_item<T: AsRef<str>>(self, arg: T) -> Builder
pub fn blocklist_item<T: AsRef<str>>(self, arg: T) -> Builder
Hide the given item from the generated bindings, regardless of whether it’s a type, function, module, etc. Regular expressions are supported.
To blocklist items prefixed with “mylib” use "mylib_.*"
.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn blocklist_file<T: AsRef<str>>(self, arg: T) -> Builder
pub fn blocklist_file<T: AsRef<str>>(self, arg: T) -> Builder
Hide any contents of the given file from the generated bindings, regardless of whether it’s a type, function, module etc. Check the regular expression arguments section and the regex crate documentation for further information.
sourcepub fn opaque_type<T: AsRef<str>>(self, arg: T) -> Builder
pub fn opaque_type<T: AsRef<str>>(self, arg: T) -> Builder
Treat the given type as opaque in the generated bindings. Regular expressions are supported.
To change types prefixed with “mylib” into opaque, use "mylib_.*"
.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn allowlist_type<T: AsRef<str>>(self, arg: T) -> Builder
pub fn allowlist_type<T: AsRef<str>>(self, arg: T) -> Builder
Allowlist the given type so that it (and all types that it transitively refers to) appears in the generated bindings. Regular expressions are supported.
To allowlist types prefixed with “mylib” use "mylib_.*"
.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn allowlist_function<T: AsRef<str>>(self, arg: T) -> Builder
pub fn allowlist_function<T: AsRef<str>>(self, arg: T) -> Builder
Allowlist the given function so that it (and all types that it transitively refers to) appears in the generated bindings. Regular expressions are supported.
Methods can be allowlisted by prefixing the name of the type
implementing them followed by an underscore. So if Foo
has a method
bar
, it can be allowlisted as Foo_bar
.
To allowlist functions prefixed with “mylib” use "mylib_.*"
.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn allowlist_var<T: AsRef<str>>(self, arg: T) -> Builder
pub fn allowlist_var<T: AsRef<str>>(self, arg: T) -> Builder
Allowlist the given variable so that it (and all types that it transitively refers to) appears in the generated bindings. Regular expressions are supported.
To allowlist variables prefixed with “mylib” use "mylib_.*"
.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn allowlist_file<T: AsRef<str>>(self, arg: T) -> Builder
pub fn allowlist_file<T: AsRef<str>>(self, arg: T) -> Builder
Allowlist the given file so that its contents appear in the generated bindings. Check the regular expression arguments section and the regex crate documentation for further information.
sourcepub fn default_enum_style(self, arg: EnumVariation) -> Builder
pub fn default_enum_style(self, arg: EnumVariation) -> Builder
Set the default style of code to generate for enums
sourcepub fn bitfield_enum<T: AsRef<str>>(self, arg: T) -> Builder
pub fn bitfield_enum<T: AsRef<str>>(self, arg: T) -> Builder
Mark the given enum (or set of enums, if using a pattern) as being bitfield-like. Regular expressions are supported.
This makes bindgen generate a type that isn’t a rust enum
. Regular
expressions are supported.
This is similar to the newtype enum style, but with the bitwise operators implemented. Check the regular expression arguments section and the regex crate documentation for further information.
sourcepub fn newtype_enum<T: AsRef<str>>(self, arg: T) -> Builder
pub fn newtype_enum<T: AsRef<str>>(self, arg: T) -> Builder
Mark the given enum (or set of enums, if using a pattern) as a newtype. Regular expressions are supported.
This makes bindgen generate a type that isn’t a Rust enum
. Regular
expressions are supported.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn newtype_global_enum<T: AsRef<str>>(self, arg: T) -> Builder
pub fn newtype_global_enum<T: AsRef<str>>(self, arg: T) -> Builder
Mark the given enum (or set of enums, if using a pattern) as a newtype whose variants are exposed as global constants.
Regular expressions are supported.
This makes bindgen generate a type that isn’t a Rust enum
. Regular
expressions are supported.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn rustified_enum<T: AsRef<str>>(self, arg: T) -> Builder
pub fn rustified_enum<T: AsRef<str>>(self, arg: T) -> Builder
Mark the given enum (or set of enums, if using a pattern) as a Rust enum.
This makes bindgen generate enums instead of constants. Regular expressions are supported.
Use this with caution, creating this in unsafe code (including FFI) with an invalid value will invoke undefined behaviour. You may want to use the newtype enum style instead. Check the regular expression arguments section and the regex crate documentation for further information.
sourcepub fn rustified_non_exhaustive_enum<T: AsRef<str>>(self, arg: T) -> Builder
pub fn rustified_non_exhaustive_enum<T: AsRef<str>>(self, arg: T) -> Builder
Mark the given enum (or set of enums, if using a pattern) as a Rust
enum with the #[non_exhaustive]
attribute.
This makes bindgen generate enums instead of constants. Regular expressions are supported.
Use this with caution, creating this in unsafe code (including FFI) with an invalid value will invoke undefined behaviour. You may want to use the newtype enum style instead. Check the regular expression arguments section and the regex crate documentation for further information.
sourcepub fn constified_enum<T: AsRef<str>>(self, arg: T) -> Builder
pub fn constified_enum<T: AsRef<str>>(self, arg: T) -> Builder
Mark the given enum (or set of enums, if using a pattern) as a set of constants that are not to be put into a module. Check the regular expression arguments section and the regex crate documentation for further information.
sourcepub fn constified_enum_module<T: AsRef<str>>(self, arg: T) -> Builder
pub fn constified_enum_module<T: AsRef<str>>(self, arg: T) -> Builder
Mark the given enum (or set of enums, if using a pattern) as a set of constants that should be put into a module.
This makes bindgen generate modules containing constants instead of just constants. Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
sourcepub fn default_macro_constant_type(self, arg: MacroTypeVariation) -> Builder
pub fn default_macro_constant_type(self, arg: MacroTypeVariation) -> Builder
Set the default type for macro constants
sourcepub fn default_alias_style(self, arg: AliasVariation) -> Builder
pub fn default_alias_style(self, arg: AliasVariation) -> Builder
Set the default style of code to generate for typedefs
sourcepub fn type_alias<T: AsRef<str>>(self, arg: T) -> Builder
pub fn type_alias<T: AsRef<str>>(self, arg: T) -> Builder
Mark the given typedef alias (or set of aliases, if using a pattern) to use regular Rust type aliasing.
This is the default behavior and should be used if default_alias_style
was set to NewType or NewTypeDeref and you want to override it for a
set of typedefs.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn new_type_alias<T: AsRef<str>>(self, arg: T) -> Builder
pub fn new_type_alias<T: AsRef<str>>(self, arg: T) -> Builder
Mark the given typedef alias (or set of aliases, if using a pattern) to be generated as a new type by having the aliased type be wrapped in a #[repr(transparent)] struct.
Used to enforce stricter type checking. Check the regular expression arguments section and the regex crate documentation for further information.
sourcepub fn new_type_alias_deref<T: AsRef<str>>(self, arg: T) -> Builder
pub fn new_type_alias_deref<T: AsRef<str>>(self, arg: T) -> Builder
Mark the given typedef alias (or set of aliases, if using a pattern) to
be generated as a new type by having the aliased type be wrapped in a
#[repr(transparent)] struct and also have an automatically generated
impl’s of Deref
and DerefMut
to their aliased type.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn default_non_copy_union_style(self, arg: NonCopyUnionStyle) -> Self
pub fn default_non_copy_union_style(self, arg: NonCopyUnionStyle) -> Self
Set the default style of code to generate for unions with a non-Copy member.
sourcepub fn bindgen_wrapper_union<T: AsRef<str>>(self, arg: T) -> Self
pub fn bindgen_wrapper_union<T: AsRef<str>>(self, arg: T) -> Self
Mark the given union (or set of union, if using a pattern) to use a bindgen-generated wrapper for its members if at least one is non-Copy. Check the regular expression arguments section and the regex crate documentation for further information.
sourcepub fn manually_drop_union<T: AsRef<str>>(self, arg: T) -> Self
pub fn manually_drop_union<T: AsRef<str>>(self, arg: T) -> Self
Mark the given union (or set of union, if using a pattern) to use
::core::mem::ManuallyDrop
for its members if at least one is non-Copy.
Note: ManuallyDrop
was stabilized in Rust 1.20.0, do not use it if your
MSRV is lower.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn raw_line<T: Into<String>>(self, arg: T) -> Self
pub fn raw_line<T: Into<String>>(self, arg: T) -> Self
Add a string to prepend to the generated bindings. The string is passed through without any modification. Check the regular expression arguments section and the regex crate documentation for further information.
sourcepub fn module_raw_line<T, U>(self, mod_: T, line: U) -> Self
pub fn module_raw_line<T, U>(self, mod_: T, line: U) -> Self
Add a given line to the beginning of module mod
.
sourcepub fn module_raw_lines<T, I>(self, mod_: T, lines: I) -> Self
pub fn module_raw_lines<T, I>(self, mod_: T, lines: I) -> Self
Add a given set of lines to the beginning of module mod
.
sourcepub fn clang_arg<T: Into<String>>(self, arg: T) -> Builder
pub fn clang_arg<T: Into<String>>(self, arg: T) -> Builder
Add an argument to be passed straight through to clang.
sourcepub fn clang_args<I>(self, iter: I) -> Builder
pub fn clang_args<I>(self, iter: I) -> Builder
Add arguments to be passed straight through to clang.
sourcepub fn emit_builtins(self) -> Builder
pub fn emit_builtins(self) -> Builder
Emit bindings for builtin definitions (for example __builtin_va_list
)
in the generated Rust.
sourcepub fn no_convert_floats(self) -> Self
pub fn no_convert_floats(self) -> Self
Avoid converting floats to f32
/f64
by default.
sourcepub fn layout_tests(self, doit: bool) -> Self
pub fn layout_tests(self, doit: bool) -> Self
Set whether layout tests should be generated.
sourcepub fn impl_debug(self, doit: bool) -> Self
pub fn impl_debug(self, doit: bool) -> Self
Set whether Debug
should be implemented, if it can not be derived automatically.
sourcepub fn impl_partialeq(self, doit: bool) -> Self
pub fn impl_partialeq(self, doit: bool) -> Self
Set whether PartialEq
should be implemented, if it can not be derived automatically.
sourcepub fn derive_copy(self, doit: bool) -> Self
pub fn derive_copy(self, doit: bool) -> Self
Set whether Copy
should be derived by default.
sourcepub fn derive_debug(self, doit: bool) -> Self
pub fn derive_debug(self, doit: bool) -> Self
Set whether Debug
should be derived by default.
sourcepub fn derive_default(self, doit: bool) -> Self
pub fn derive_default(self, doit: bool) -> Self
Set whether Default
should be derived by default.
sourcepub fn derive_hash(self, doit: bool) -> Self
pub fn derive_hash(self, doit: bool) -> Self
Set whether Hash
should be derived by default.
sourcepub fn derive_partialord(self, doit: bool) -> Self
pub fn derive_partialord(self, doit: bool) -> Self
Set whether PartialOrd
should be derived by default.
If we don’t compute partialord, we also cannot compute
ord. Set the derive_ord to false
when doit is false
.
sourcepub fn derive_ord(self, doit: bool) -> Self
pub fn derive_ord(self, doit: bool) -> Self
Set whether Ord
should be derived by default.
We can’t compute Ord
without computing PartialOrd
,
so we set the same option to derive_partialord.
sourcepub fn derive_partialeq(self, doit: bool) -> Self
pub fn derive_partialeq(self, doit: bool) -> Self
Set whether PartialEq
should be derived by default.
If we don’t derive PartialEq
, we also cannot derive Eq
, so deriving
Eq
is also disabled when doit
is false
.
sourcepub fn derive_eq(self, doit: bool) -> Self
pub fn derive_eq(self, doit: bool) -> Self
Set whether Eq
should be derived by default.
We can’t derive Eq
without also deriving PartialEq
, so we also
enable deriving PartialEq
when doit
is true
.
sourcepub fn time_phases(self, doit: bool) -> Self
pub fn time_phases(self, doit: bool) -> Self
Set whether or not to time bindgen phases, and print information to stderr.
sourcepub fn emit_clang_ast(self) -> Builder
pub fn emit_clang_ast(self) -> Builder
Emit Clang AST.
sourcepub fn enable_cxx_namespaces(self) -> Builder
pub fn enable_cxx_namespaces(self) -> Builder
Enable C++ namespaces.
sourcepub fn enable_function_attribute_detection(self) -> Self
pub fn enable_function_attribute_detection(self) -> Self
Enable detecting must_use attributes on C functions.
This is quite slow in some cases (see #1465), so it’s disabled by default.
Note that for this to do something meaningful for now at least, the rust
target version has to have support for #[must_use]
.
sourcepub fn disable_name_namespacing(self) -> Builder
pub fn disable_name_namespacing(self) -> Builder
Disable name auto-namespacing.
By default, bindgen mangles names like foo::bar::Baz
to look like
foo_bar_Baz
instead of just Baz
.
This method disables that behavior.
Note that this intentionally does not change the names used for allowlisting and blocklisting, which should still be mangled with the namespaces.
Note, also, that this option may cause bindgen to generate duplicate names.
sourcepub fn disable_nested_struct_naming(self) -> Builder
pub fn disable_nested_struct_naming(self) -> Builder
Disable nested struct naming.
The following structs have different names for C and C++. In case of C
they are visible as foo
and bar
. In case of C++ they are visible as
foo
and foo::bar
.
struct foo {
struct bar {
} b;
};
Bindgen wants to avoid duplicate names by default so it follows C++ naming
and it generates foo
/foo_bar
instead of just foo
/bar
.
This method disables this behavior and it is indented to be used only for headers that were written for C.
sourcepub fn conservative_inline_namespaces(self) -> Builder
pub fn conservative_inline_namespaces(self) -> Builder
Treat inline namespaces conservatively.
This is tricky, because in C++ is technically legal to override an item defined in an inline namespace:
inline namespace foo {
using Bar = int;
}
using Bar = long;
Even though referencing Bar
is a compiler error.
We want to support this (arguably esoteric) use case, but we don’t want to make the rest of bindgen users pay an usability penalty for that.
To support this, we need to keep all the inline namespaces around, but
then bindgen usage is a bit more difficult, because you cannot
reference, e.g., std::string
(you’d need to use the proper inline
namespace).
We could complicate a lot of the logic to detect name collisions, and if
not detected generate a pub use inline_ns::*
or something like that.
That’s probably something we can do if we see this option is needed in a lot of cases, to improve it’s usability, but my guess is that this is not going to be too useful.
sourcepub fn generate_inline_functions(self, doit: bool) -> Self
pub fn generate_inline_functions(self, doit: bool) -> Self
Whether inline functions should be generated or not.
Note that they will usually not work. However you can use
-fkeep-inline-functions
or -fno-inline-functions
if you are
responsible of compiling the library to make them callable.
sourcepub fn ignore_functions(self) -> Builder
pub fn ignore_functions(self) -> Builder
Ignore functions.
sourcepub fn ignore_methods(self) -> Builder
pub fn ignore_methods(self) -> Builder
Ignore methods.
sourcepub fn ctypes_prefix<T: Into<String>>(self, prefix: T) -> Builder
pub fn ctypes_prefix<T: Into<String>>(self, prefix: T) -> Builder
Use the given prefix for the raw types instead of ::std::os::raw
.
sourcepub fn anon_fields_prefix<T: Into<String>>(self, prefix: T) -> Builder
pub fn anon_fields_prefix<T: Into<String>>(self, prefix: T) -> Builder
Use the given prefix for the anon fields.
sourcepub fn parse_callbacks(self, cb: Box<dyn ParseCallbacks>) -> Self
pub fn parse_callbacks(self, cb: Box<dyn ParseCallbacks>) -> Self
Allows configuring types in different situations, see the
ParseCallbacks
documentation.
sourcepub fn with_codegen_config(self, config: CodegenConfig) -> Self
pub fn with_codegen_config(self, config: CodegenConfig) -> Self
Choose what to generate using a
CodegenConfig
.
sourcepub fn detect_include_paths(self, doit: bool) -> Self
pub fn detect_include_paths(self, doit: bool) -> Self
Whether to detect include paths using clang_sys.
sourcepub fn fit_macro_constants(self, doit: bool) -> Self
pub fn fit_macro_constants(self, doit: bool) -> Self
Whether to try to fit macro constants to types smaller than u32/i32
sourcepub fn prepend_enum_name(self, doit: bool) -> Self
pub fn prepend_enum_name(self, doit: bool) -> Self
Prepend the enum name to constant or newtype variants.
sourcepub fn size_t_is_usize(self, is: bool) -> Self
pub fn size_t_is_usize(self, is: bool) -> Self
Set whether size_t
should be translated to usize
automatically.
sourcepub fn rustfmt_bindings(self, doit: bool) -> Self
pub fn rustfmt_bindings(self, doit: bool) -> Self
Set whether rustfmt should format the generated bindings.
sourcepub fn record_matches(self, doit: bool) -> Self
pub fn record_matches(self, doit: bool) -> Self
Set whether we should record matched items in our regex sets.
sourcepub fn rustfmt_configuration_file(self, path: Option<PathBuf>) -> Self
pub fn rustfmt_configuration_file(self, path: Option<PathBuf>) -> Self
Set the absolute path to the rustfmt configuration file, if None, the standard rustfmt options are used.
sourcepub fn with_rustfmt<P: Into<PathBuf>>(self, path: P) -> Self
pub fn with_rustfmt<P: Into<PathBuf>>(self, path: P) -> Self
Sets an explicit path to rustfmt, to be used when rustfmt is enabled.
sourcepub fn explicit_padding(self, doit: bool) -> Self
pub fn explicit_padding(self, doit: bool) -> Self
If true, always emit explicit padding fields.
If a struct needs to be serialized in its native format (padding bytes and all), for example writing it to a file or sending it on the network, then this should be enabled, as anything reading the padding bytes of a struct may lead to Undefined Behavior.
sourcepub fn vtable_generation(self, doit: bool) -> Self
pub fn vtable_generation(self, doit: bool) -> Self
If true, enables experimental support to generate vtable functions.
Should mostly work, though some edge cases are likely to be broken.
sourcepub fn sort_semantically(self, doit: bool) -> Self
pub fn sort_semantically(self, doit: bool) -> Self
If true, enables the sorting of the output in a predefined manner.
TODO: Perhaps move the sorting order out into a config
sourcepub fn merge_extern_blocks(self, doit: bool) -> Self
pub fn merge_extern_blocks(self, doit: bool) -> Self
If true, merges extern blocks.
sourcepub fn generate(self) -> Result<Bindings, BindgenError>
pub fn generate(self) -> Result<Bindings, BindgenError>
Generate the Rust bindings using the options built up thus far.
sourcepub fn dump_preprocessed_input(&self) -> Result<()>
pub fn dump_preprocessed_input(&self) -> Result<()>
Preprocess and dump the input header files to disk.
This is useful when debugging bindgen, using C-Reduce, or when filing
issues. The resulting file will be named something like __bindgen.i
or
__bindgen.ii
sourcepub fn no_partialeq<T: Into<String>>(self, arg: T) -> Builder
pub fn no_partialeq<T: Into<String>>(self, arg: T) -> Builder
Don’t derive PartialEq
for a given type. Regular
expressions are supported.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn no_copy<T: Into<String>>(self, arg: T) -> Self
pub fn no_copy<T: Into<String>>(self, arg: T) -> Self
Don’t derive Copy
for a given type. Regular
expressions are supported.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn no_debug<T: Into<String>>(self, arg: T) -> Self
pub fn no_debug<T: Into<String>>(self, arg: T) -> Self
Don’t derive Debug
for a given type. Regular
expressions are supported.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn no_default<T: Into<String>>(self, arg: T) -> Self
pub fn no_default<T: Into<String>>(self, arg: T) -> Self
Don’t derive/impl Default
for a given type. Regular
expressions are supported.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn no_hash<T: Into<String>>(self, arg: T) -> Builder
pub fn no_hash<T: Into<String>>(self, arg: T) -> Builder
Don’t derive Hash
for a given type. Regular
expressions are supported.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn must_use_type<T: Into<String>>(self, arg: T) -> Builder
pub fn must_use_type<T: Into<String>>(self, arg: T) -> Builder
Add #[must_use]
for the given type. Regular
expressions are supported.
Check the regular expression arguments section and the regex crate
documentation for further information.
sourcepub fn array_pointers_in_arguments(self, doit: bool) -> Self
pub fn array_pointers_in_arguments(self, doit: bool) -> Self
Set whether arr[size]
should be treated as *mut T
or *mut [T; size]
(same for mut)
sourcepub fn wasm_import_module_name<T: Into<String>>(self, import_name: T) -> Self
pub fn wasm_import_module_name<T: Into<String>>(self, import_name: T) -> Self
Set the wasm import module name
sourcepub fn dynamic_library_name<T: Into<String>>(
self,
dynamic_library_name: T,
) -> Self
pub fn dynamic_library_name<T: Into<String>>( self, dynamic_library_name: T, ) -> Self
Specify the dynamic library name if we are generating bindings for a shared library.
sourcepub fn dynamic_link_require_all(self, req: bool) -> Self
pub fn dynamic_link_require_all(self, req: bool) -> Self
Require successful linkage for all routines in a shared library. This allows us to optimize function calls by being able to safely assume function pointers are valid.
sourcepub fn respect_cxx_access_specs(self, doit: bool) -> Self
pub fn respect_cxx_access_specs(self, doit: bool) -> Self
Generate bindings as pub
only if the bound item is publically accessible by C++.
sourcepub fn translate_enum_integer_types(self, doit: bool) -> Self
pub fn translate_enum_integer_types(self, doit: bool) -> Self
Always translate enum integer types to native Rust integer types.
This will result in enums having types such as u32
and i16
instead
of c_uint
and c_short
. Types for Rustified enums are always
translated.
sourcepub fn c_naming(self, doit: bool) -> Self
pub fn c_naming(self, doit: bool) -> Self
Generate types with C style naming.
This will add prefixes to the generated type names. For example instead of a struct A
we
will generate struct struct_A
. Currently applies to structs, unions, and enums.
sourcepub fn override_abi<T: Into<String>>(self, abi: Abi, arg: T) -> Self
pub fn override_abi<T: Into<String>>(self, abi: Abi, arg: T) -> Self
Override the ABI of a given function. Regular expressions are supported.
sourcepub fn wrap_unsafe_ops(self, doit: bool) -> Self
pub fn wrap_unsafe_ops(self, doit: bool) -> Self
If true, wraps unsafe operations in unsafe blocks.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Builder
impl !RefUnwindSafe for Builder
impl !Send for Builder
impl !Sync for Builder
impl Unpin for Builder
impl !UnwindSafe for Builder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more