Struct Builder
struct Builder { ... }
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:
constified_enum_module()bitfield_enum()newtype_enum()rustified_enum()rustified_non_exhaustive_enum()
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_ARGSenvironment 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, such as allowlist_* and blocklist_*, allow regular
expressions as arguments. These regular expressions will be enclosed in parentheses and
anchored with ^ and $. So, if the argument passed is <regex>, the regular expression to be
stored will be ^(<regex>)$.
As a consequence, regular expressions passed to bindgen will try to match the whole name of
an item instead of a section of it, which means that to match any items with the prefix
prefix, the prefix.* regular expression must be used.
Certain methods, like Builder::allowlist_function, use regular expressions over function
names. To match C++ methods, prefix the name of the type where they belong, followed by an
underscore. So, if the type Foo has a method bar, it can be matched with the Foo_bar
regular expression.
Additionally, Objective-C interfaces can be matched by prefixing the regular expression with
I. For example, the IFoo regular expression matches the Foo interface, and the IFoo_foo
regular expression matches the foo method of the Foo interface.
Releases of bindgen with a version lesser or equal to 0.62.0 used to accept the wildcard
pattern * as a valid regular expression. This behavior has been deprecated, and the .*
regular expression must be used instead.
Implementations
impl Builder
fn command_line_flags(self: &Self) -> Vec<String>Generates the command line flags used to create this
Builder.fn use_specific_virtual_function_receiver(self: Self, doit: bool) -> BuilderNormally, virtual functions have void* as their 'this' type. If this flag is enabled, override that behavior to indicate a pointer of the specific type. Disabled by default.
fn use_distinct_char16_t(self: Self, doit: bool) -> BuilderIf this is true, denote 'char16_t' as a separate type from 'u16' Disabled by default.
fn represent_cxx_operators(self: Self, doit: bool) -> BuilderIf this is true, output existence of C++ overloaded operators. At present, only operator= is noted. Disabled by default.
fn blocklist_type<T: AsRef<str>>(self: Self, arg: T) -> BuilderDo not generate any bindings for the given type.
This option is not recursive, meaning that it will only block types whose names explicitly match the argument of this method.
Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn blocklist_function<T: AsRef<str>>(self: Self, arg: T) -> BuilderDo not generate any bindings for the given function.
This option is not recursive, meaning that it will only block functions whose names explicitly match the argument of this method.
Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn blocklist_item<T: AsRef<str>>(self: Self, arg: T) -> BuilderDo not generate any bindings for the given item, regardless of whether it is a type, function, module, etc.
This option is not recursive, meaning that it will only block items whose names explicitly match the argument of this method.
Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn blocklist_file<T: AsRef<str>>(self: Self, arg: T) -> BuilderDo not generate any bindings for the contents of the given file, regardless of whether the contents of the file are types, functions, modules, etc.
This option is not recursive, meaning that it will only block files whose names explicitly match the argument of this method.
This method will use the argument to match the complete path of the file instead of a section of it.
Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn blocklist_var<T: AsRef<str>>(self: Self, arg: T) -> BuilderDo not generate any bindings for the given variable.
This option is not recursive, meaning that it will only block variables whose names explicitly match the argument of this method.
Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn opaque_type<T: AsRef<str>>(self: Self, arg: T) -> BuilderTreat the given type as opaque in the generated bindings.
Opaque in this context means that none of the generated bindings will contain information about the inner representation of the type and the type itself will be represented as a chunk of bytes with the alignment and size of the type.
Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn with_rustfmt<P: Into<PathBuf>>(self: Self, path: P) -> SelfSet an explicit path to the
rustfmtbinary.This option only comes into effect if
rustfmtis set to be the formatter used bybindgen. Check the documentation of theBuilder::formattermethod for more information.fn depfile<H: Into<String>, D: Into<PathBuf>>(self: Self, output_module: H, depfile: D) -> BuilderAdd a depfile output which will be written alongside the generated bindings.
fn allowlist_type<T: AsRef<str>>(self: Self, arg: T) -> BuilderGenerate bindings for the given type.
This option is transitive by default. Check the documentation of the
Builder::allowlist_recursivelymethod for further information.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn allowlist_function<T: AsRef<str>>(self: Self, arg: T) -> BuilderGenerate bindings for the given function.
This option is transitive by default. Check the documentation of the
Builder::allowlist_recursivelymethod for further information.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn allowlist_var<T: AsRef<str>>(self: Self, arg: T) -> BuilderGenerate bindings for the given variable.
This option is transitive by default. Check the documentation of the
Builder::allowlist_recursivelymethod for further information.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn allowlist_file<T: AsRef<str>>(self: Self, arg: T) -> BuilderGenerate bindings for the content of the given file.
This option is transitive by default. Check the documentation of the
Builder::allowlist_recursivelymethod for further information.This method will use the argument to match the complete path of the file instead of a section of it.
Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn allowlist_item<T: AsRef<str>>(self: Self, arg: T) -> BuilderGenerate bindings for the given item, regardless of whether it is a type, function, module, etc.
This option is transitive by default. Check the documentation of the
Builder::allowlist_recursivelymethod for further information.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn default_enum_style(self: Self, arg: EnumVariation) -> BuilderSet the default style for generated
enums.If this method is not called, the
EnumVariation::Constsstyle will be used by default.To set the style for individual
enums, useBuilder::bitfield_enum,Builder::newtype_enum,Builder::newtype_global_enum,Builder::rustified_enum,Builder::rustified_non_exhaustive_enum,Builder::constified_enum_moduleorBuilder::constified_enum.fn bitfield_enum<T: AsRef<str>>(self: Self, arg: T) -> BuilderMark the given
enumas being bitfield-like.This is similar to the
Builder::newtype_enumstyle, but with the bitwise operators implemented.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn newtype_enum<T: AsRef<str>>(self: Self, arg: T) -> BuilderMark the given
enumas a newtype.This means that an integer newtype will be declared to represent the
enumtype and its variants will be represented as constants inside of this type'simplblock.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn newtype_global_enum<T: AsRef<str>>(self: Self, arg: T) -> BuilderMark the given
enumas a global newtype.This is similar to the
Builder::newtype_enumstyle, but the constants for each variant are free constants instead of being declared inside animplblock for the newtype.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn rustified_enum<T: AsRef<str>>(self: Self, arg: T) -> BuilderMark the given
enumas a Rustenum.This means that each variant of the
enumwill be represented as a Rustenumvariant.Use this with caution, creating an instance of a Rust
enumwith an invalid value will cause undefined behaviour. To avoid this, use theBuilder::newtype_enumstyle instead.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn rustified_non_exhaustive_enum<T: AsRef<str>>(self: Self, arg: T) -> BuilderMark the given
enumas a non-exhaustive Rustenum.This is similar to the
Builder::rustified_enumstyle, but theenumis tagged with the#[non_exhaustive]attribute.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn constified_enum_module<T: AsRef<str>>(self: Self, arg: T) -> BuilderMark the given
enumas a module with a set of integer constants.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn constified_enum<T: AsRef<str>>(self: Self, arg: T) -> BuilderMark the given
enumas a set of integer constants.This is similar to the
Builder::constified_enum_modulestyle, but the constants are generated in the current module instead of in a new module.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn default_macro_constant_type(self: Self, arg: MacroTypeVariation) -> BuilderSet the default type signedness to be used for macro constants.
If this method is not called,
MacroTypeVariation::Unsignedis used by default.To set the type for individual macro constants, use the
ParseCallbacks::int_macromethod.fn default_alias_style(self: Self, arg: AliasVariation) -> BuilderSet the default style of code generation for
typedefs.If this method is not called, the
AliasVariation::TypeAliasstyle is used by default.To set the style for individual
typedefss, useBuilder::type_alias,Builder::new_type_aliasorBuilder::new_type_alias_deref.fn type_alias<T: AsRef<str>>(self: Self, arg: T) -> BuilderMark the given
typedefas a regular Rusttypealias.This is the default behavior, meaning that this method only comes into effect if a style different from
AliasVariation::TypeAliaswas passed to theBuilder::default_alias_stylemethod.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn new_type_alias<T: AsRef<str>>(self: Self, arg: T) -> BuilderMark the given
typedefas a Rust newtype by having the aliased type be wrapped in astructwith#[repr(transparent)].This method can be used to enforce stricter type checking.
Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn new_type_alias_deref<T: AsRef<str>>(self: Self, arg: T) -> BuilderMark the given
typedefto be generated as a newtype that can be dereferenced.This is similar to the
Builder::new_type_aliasstyle, but the newtype implementsDerefandDerefMutwith the aliased type as a target.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn default_non_copy_union_style(self: Self, arg: NonCopyUnionStyle) -> SelfSet the default style of code to generate for
unions with non-Copymembers.If this method is not called, the
NonCopyUnionStyle::BindgenWrapperstyle is used by default.To set the style for individual
unions, useBuilder::bindgen_wrapper_unionorBuilder::manually_drop_union.fn bindgen_wrapper_union<T: AsRef<str>>(self: Self, arg: T) -> SelfMark the given
unionto use abindgen-generated wrapper for its members if at least one them is notCopy.This is the default behavior, meaning that this method only comes into effect if a style different from
NonCopyUnionStyle::BindgenWrapperwas passed to theBuilder::default_non_copy_union_stylemethod.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn manually_drop_union<T: AsRef<str>>(self: Self, arg: T) -> SelfMark the given
unionto use::core::mem::ManuallyDropfor its members if at least one of them is notCopy.The
ManuallyDroptype was stabilized in Rust 1.20.0, do not use this option if your target version is lower than this.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn emit_builtins(self: Self) -> BuilderGenerate Rust bindings for built-in definitions (for example
__builtin_va_list).Bindings for built-in definitions are not emitted by default.
fn emit_clang_ast(self: Self) -> BuilderEmit the Clang AST to
stdoutfor debugging purposes.The Clang AST is not emitted by default.
fn emit_ir(self: Self) -> BuilderEmit the
bindgeninternal representation tostdoutfor debugging purposes.This internal representation is not emitted by default.
fn emit_ir_graphviz<T: Into<String>>(self: Self, path: T) -> BuilderSet the path for the file where the
bindgeninternal representation will be emitted as a graph using thegraphvizDOT language.This graph representation is not emitted by default.
fn enable_cxx_namespaces(self: Self) -> BuilderEmulate C++ namespaces using Rust modules in the generated bindings.
C++ namespaces are not emulated by default.
fn enable_function_attribute_detection(self: Self) -> SelfEnable detecting function attributes on C functions.
This enables the following features:
- Add
#[must_use]attributes to Rust items whose C counterparts are marked as so. This feature also requires that the Rust target version supports the attribute. - Set
!as the return type for Rust functions whose C counterparts are marked as diverging.
This option can be quite slow in some cases (check #1465), so it is disabled by default.
- Add
fn disable_name_namespacing(self: Self) -> BuilderDisable name auto-namespacing.
By default,
bindgenmangles names likefoo::bar::Bazto look likefoo_bar_Bazinstead of justBaz. This method disables that behavior.Note that this does not change the names used for allowlisting and blocklisting, which should still be mangled with the namespaces. Additionally, this option may cause
bindgento generate duplicate names.fn disable_nested_struct_naming(self: Self) -> BuilderDisable nested
structnaming.The following
structs have different names for C and C++. In C, they are visible asfooandbar. In C++, they are visible asfooandfoo::bar.;bindgentries to avoid duplicate names by default, so it follows the C++ naming convention and it generatesfooandfoo_barinstead of justfooandbar.This method disables this behavior and it is indented to be used only for headers that were written in C.
fn disable_header_comment(self: Self) -> SelfDo not insert the
bindgenversion identifier into the generated bindings.This identifier is inserted by default.
fn layout_tests(self: Self, doit: bool) -> SelfSet whether layout tests should be generated.
Layout tests are generated by default.
fn impl_debug(self: Self, doit: bool) -> SelfSet whether
Debugshould be implemented for types that cannot derive it.This option is disabled by default.
fn impl_partialeq(self: Self, doit: bool) -> SelfSet whether
PartialEqshould be implemented for types that cannot derive it.This option is disabled by default.
fn derive_copy(self: Self, doit: bool) -> SelfSet whether the
Copytrait should be derived when possible.Copyis derived by default.fn derive_debug(self: Self, doit: bool) -> SelfSet whether the
Debugtrait should be derived when possible.The
Builder::impl_debugmethod can be used to implementDebugfor types that cannot derive it.Debugis derived by default.fn derive_default(self: Self, doit: bool) -> SelfSet whether the
Defaulttrait should be derived when possible.Defaultis not derived by default.fn derive_hash(self: Self, doit: bool) -> SelfSet whether the
Hashtrait should be derived when possible.Hashis not derived by default.fn derive_partialord(self: Self, doit: bool) -> SelfSet whether the
PartialOrdtrait should be derived when possible.Take into account that
Ordcannot be derived for a type that does not implementPartialOrd. For this reason, setting this method tofalsealso sets automaticallyBuilder::derive_ordtofalse.PartialOrdis not derived by default.fn derive_ord(self: Self, doit: bool) -> SelfSet whether the
Ordtrait should be derived when possible.Take into account that
Ordcannot be derived for a type that does not implementPartialOrd. For this reason, the value set with this method will also be set automatically forBuilder::derive_partialord.Ordis not derived by default.fn derive_partialeq(self: Self, doit: bool) -> SelfSet whether the
PartialEqtrait should be derived when possible.Take into account that
Eqcannot be derived for a type that does not implementPartialEq. For this reason, setting this method tofalsealso sets automaticallyBuilder::derive_eqtofalse.The
Builder::impl_partialeqmethod can be used to implementPartialEqfor types that cannot derive it.PartialEqis not derived by default.fn derive_eq(self: Self, doit: bool) -> SelfSet whether the
Eqtrait should be derived when possible.Take into account that
Eqcannot be derived for a type that does not implementPartialEq. For this reason, the value set with this method will also be set automatically forBuilder::derive_partialeq.Eqis not derived by default.fn use_core(self: Self) -> BuilderUse
coreinstead ofstdin the generated bindings.stdis used by default.fn ctypes_prefix<T: Into<String>>(self: Self, prefix: T) -> BuilderUse the given prefix for the C platform-specific types instead of
::std::os::raw.Alternatively, the
Builder::use_coremethod can be used to set the prefix to::core::ffior::core::os::raw.fn anon_fields_prefix<T: Into<String>>(self: Self, prefix: T) -> BuilderUse the given prefix for the anonymous fields.
An anonymous field, is a field of a C/C++ type that does not have a name. For example, in the following C code:
The only field of the
integerstructis an anonymous field and its Rust representation will be named using this prefix followed by an integer identifier.The default prefix is
__bindgen_anon_.fn time_phases(self: Self, doit: bool) -> SelfSet whether to measure the elapsed time for each one of the
bindgenphases. This information is printed tostderr.The elapsed time is not measured by default.
fn no_convert_floats(self: Self) -> SelfAvoid converting C float types to
f32andf64.fn raw_line<T: Into<String>>(self: Self, arg: T) -> SelfAdd a line of Rust code at the beginning of the generated bindings. The string is passed through without any modification.
fn module_raw_line<T, U>(self: Self, module: T, line: U) -> Self where T: Into<String>, U: Into<String>Add a given line to the beginning of a given module.
This option only comes into effect if the
Builder::enable_cxx_namespacesmethod is also being called.fn header<T: Into<String>>(self: Self, header: T) -> BuilderAdd an input C/C++ header to generate bindings for.
This can be used to generate bindings for a single header:
let bindings = bindgen::Builder::default() .header("input.h") .generate() .unwrap();Or for multiple headers:
let bindings = bindgen::Builder::default() .header("first.h") .header("second.h") .header("third.h") .generate() .unwrap();fn headers<I: IntoIterator>(self: Self, headers: I) -> Builder where <I as >::Item: Into<String>Add input C/C++ header(s) to generate bindings for.
This can be used to generate bindings for a single header:
let bindings = bindgen::Builder::default() .headers(["input.h"]) .generate() .unwrap();Or for multiple headers:
let bindings = bindgen::Builder::default() .headers(["first.h", "second.h", "third.h"]) .generate() .unwrap();fn clang_arg<T: Into<String>>(self: Self, arg: T) -> BuilderAdd an argument to be passed straight through to Clang.
fn clang_args<I: IntoIterator>(self: Self, args: I) -> Builder where <I as >::Item: AsRef<str>Add several arguments to be passed straight through to Clang.
fn header_contents(self: Self, name: &str, contents: &str) -> BuilderAdd
contentsas an input C/C++ header namedname.This can be used to inject additional C/C++ code as an input without having to create additional header files.
fn parse_callbacks(self: Self, cb: Box<dyn ParseCallbacks>) -> SelfAdd a new
ParseCallbacksinstance to configure types in different situations.This can also be used with
CargoCallbacksto emitcargo:rerun-if-changed=...for all#included header files.fn ignore_functions(self: Self) -> BuilderDo not generate any functions.
Functions are generated by default.
fn ignore_methods(self: Self) -> BuilderDo not generate any methods.
Methods are generated by default.
fn with_codegen_config(self: Self, config: CodegenConfig) -> SelfChoose what to generate using a
CodegenConfig.This option overlaps with
Builder::ignore_functionsandBuilder::ignore_methods.All the items in
CodegenConfigare generated by default.fn conservative_inline_namespaces(self: Self) -> BuilderTreat inline namespaces conservatively.
This is tricky, because in C++ is technically legal to override an item defined in an inline namespace:
inline using Bar = long;Even though referencing
Baris a compiler error.We want to support this (arguably esoteric) use case, but we do not want to make the rest of
bindgenusers pay an usability penalty for that.To support this, we need to keep all the inline namespaces around, but then using
bindgenbecomes a bit more difficult, because you cannot reference paths likestd::string(you'd need to use the proper inline namespace).We could complicate a lot of the logic to detect name collisions and, in the absence of collisions, generate a
pub use inline_ns::*or something like that.That is probably something we can do to improve the usability of this option if we realize it is needed way more often. Our guess is that this extra logic is not going to be very useful.
This option is disabled by default.
fn generate_comments(self: Self, doit: bool) -> SelfSet whether the generated bindings should contain documentation comments.
Documentation comments are included by default.
Note that clang excludes comments from system headers by default, pass
"-fretain-comments-from-system-headers"to theBuilder::clang_argmethod to include them.It is also possible to process all comments and not just documentation using the
"-fparse-all-comments"flag. Check these slides on clang comment parsing for more information and examples.fn generate_inline_functions(self: Self, doit: bool) -> SelfSet whether to generate inline functions.
This option is disabled by default.
Note that they will usually not work. However you can use
-fkeep-inline-functionsor-fno-inline-functionsif you are responsible of compiling the library to make them callable.Check the
Builder::wrap_static_fnsmethod for an alternative.fn allowlist_recursively(self: Self, doit: bool) -> SelfSet whether to recursively allowlist items.
Items are allowlisted recursively by default.
Given that we have explicitly allowlisted the
initiate_dance_partyfunction in this C header:typedef struct MoonBoots MoonBoots; void ;We would normally generate bindings to both the
initiate_dance_partyfunction and theMoonBootstype that it transitively references. Iffalseis passed to this method,bindgenwill not emit bindings for anything except the explicitly allowlisted items, meaning that the definition forMoonBootswould not be generated. However, theinitiate_dance_partyfunction would still referenceMoonBoots!Disabling this feature will almost certainly cause
bindgento 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 missing definitions is by using theBuilder::raw_linemethod, another would be to define them in Rust and theninclude!(...)the bindings immediately afterwards.fn objc_extern_crate(self: Self, doit: bool) -> SelfEmit
#[macro_use] extern crate objc;instead ofuse objc;in the prologue of the files generated from objective-c files.use objc;is emitted by default.fn generate_block(self: Self, doit: bool) -> SelfGenerate proper block signatures instead of
voidpointers.voidpointers are used by default.fn generate_cstr(self: Self, doit: bool) -> SelfSet whether string constants should be generated as
&CStrinstead of&[u8].A minimum Rust target of 1.59 is required for this to have any effect as support for
CStr::from_bytes_with_nul_uncheckedinconstcontexts is needed.This option is disabled by default but will become enabled by default in a future release, so enabling this is recommended.
fn block_extern_crate(self: Self, doit: bool) -> SelfEmit
#[macro_use] extern crate block;instead ofuse block;in the prologue of the files generated from apple block files.use block;is emitted by default.fn trust_clang_mangling(self: Self, doit: bool) -> SelfSet whether to use the clang-provided name mangling. This is probably needed for C++ features.
The mangling provided by clang is used by default.
We allow disabling this option because some old
libclangversions seem to return incorrect results in some cases for non-mangled functions, check #528 for more information.fn detect_include_paths(self: Self, doit: bool) -> SelfSet whether to detect include paths using
clang_sys.clang_sysis used to detect include paths by default.fn fit_macro_constants(self: Self, doit: bool) -> SelfSet whether
bindgenshould try to fit macro constants into types smaller thanu32andi32.This option is disabled by default.
fn prepend_enum_name(self: Self, doit: bool) -> SelfSet whether to prepend the
enumname to constant or newtype variants.The
enumname is prepended by default.fn rust_target(self: Self, rust_target: RustTarget) -> SelfSpecify the Rust target version.
The default target is the latest stable Rust version.
fn rust_edition(self: Self, rust_edition: RustEdition) -> SelfSpecify the Rust target edition.
The default edition is the latest edition supported by the chosen Rust target.
fn disable_untagged_union(self: Self) -> SelfDisable support for native Rust unions, if supported.
The default value of this option is set based on the value passed to
Builder::rust_target.fn record_matches(self: Self, doit: bool) -> SelfSet whether we should record which items in our regex sets did match any C items.
Matches are recorded by default.
fn size_t_is_usize(self: Self, is: bool) -> SelfSet whether
size_tshould be translated tousize.If
size_tis translated tousize, type definitions forsize_twill not be emitted.size_tis translated tousizeby default.fn rustfmt_bindings(self: Self, doit: bool) -> SelfSet whether
rustfmtshould be used to format the generated bindings.rustfmtis used by default.This method overlaps in functionality with the more general
Builder::formatter. Thus, the latter should be preferred.fn formatter(self: Self, formatter: Formatter) -> SelfSet which tool should be used to format the generated bindings.
The default formatter is
Formatter::Rustfmt.To be able to use
prettypleaseas a formatter, the"prettyplease"feature forbindgenmust be enabled in the Cargo manifest.fn rustfmt_configuration_file(self: Self, path: Option<PathBuf>) -> SelfSet the absolute path to the
rustfmtconfiguration file.The default
rustfmtoptions are used ifNoneis passed to this method or if this method is not called at all.Calling this method will set the
Builder::rustfmt_bindingsoption totrueand theBuilder::formatteroption toFormatter::Rustfmt.fn no_partialeq<T: Into<String>>(self: Self, arg: T) -> BuilderDo not derive
PartialEqfor a given type.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn no_copy<T: Into<String>>(self: Self, arg: T) -> SelfDo not derive
CopyandClonefor a given type.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn no_debug<T: Into<String>>(self: Self, arg: T) -> SelfDo not derive
Debugfor a given type.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn no_default<T: Into<String>>(self: Self, arg: T) -> SelfDo not derive or implement
Defaultfor a given type.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn no_hash<T: Into<String>>(self: Self, arg: T) -> BuilderDo not derive
Hashfor a given type.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn must_use_type<T: Into<String>>(self: Self, arg: T) -> BuilderAnnotate the given type with the
#[must_use]attribute.Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn array_pointers_in_arguments(self: Self, doit: bool) -> SelfTranslate arrays
T arr[size]into array pointers*mut [T; size]instead of translating them as*mut Twhich is the default.The same is done for
*constpointers.fn wasm_import_module_name<T: Into<String>>(self: Self, import_name: T) -> SelfAdds the
#[link(wasm_import_module = import_name)]attribute to all theexternblocks generated bybindgen.This attribute is not added by default.
fn dynamic_library_name<T: Into<String>>(self: Self, dynamic_library_name: T) -> SelfGenerate bindings for a shared library with the given name.
This option is disabled by default.
fn dynamic_link_require_all(self: Self, req: bool) -> SelfSet whether to 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.
This option only comes into effect if the
Builder::dynamic_library_nameoption is set.This option is disabled by default.
fn respect_cxx_access_specs(self: Self, doit: bool) -> SelfSet whether to respect the C++ access specifications.
Passing
trueto this method will set the visibility of the generated Rust items aspubonly if the corresponding C++ items are publicly accessible instead of marking all the items as public, which is the default.fn translate_enum_integer_types(self: Self, doit: bool) -> SelfSet whether to always translate
enuminteger types to native Rust integer types.Passing
trueto this method will result inenums having types such asu32andi16instead ofc_uintandc_shortwhich is the default. The#[repr]types of Rustenums are always translated to Rust integer types.fn c_naming(self: Self, doit: bool) -> SelfSet whether to generate types with C style naming.
Passing
trueto this method will add prefixes to the generated type names. For example, instead of astructwith nameAwe will generate astructwithstruct_A. Currently applies tostructs,unions, andenums.fn explicit_padding(self: Self, doit: bool) -> SelfSet whether to always emit explicit padding fields.
This option should be enabled if a
structneeds to be serialized in its native format (padding bytes and all). This could be required if suchstructwill be written to a file or sent over the network, as anything reading the padding bytes of a struct may cause undefined behavior.Padding fields are not emitted by default.
fn vtable_generation(self: Self, doit: bool) -> SelfSet whether to enable experimental support to generate virtual table functions.
This option should mostly work, though some edge cases are likely to be broken.
Virtual table generation is disabled by default.
fn sort_semantically(self: Self, doit: bool) -> SelfSet whether to sort the generated Rust items in a predefined manner.
Items are not ordered by default.
fn merge_extern_blocks(self: Self, doit: bool) -> SelfMerge all extern blocks under the same module into a single one.
Extern blocks are not merged by default.
fn wrap_unsafe_ops(self: Self, doit: bool) -> SelfWrap all unsafe operations in unsafe blocks.
Unsafe operations are not wrapped by default.
fn flexarray_dst(self: Self, doit: bool) -> SelfUse DSTs to represent structures with flexible array members.
This option is disabled by default.
fn override_abi<T: Into<String>>(self: Self, abi: Abi, arg: T) -> SelfOverride the ABI of a given function.
Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.
fn wrap_static_fns(self: Self, doit: bool) -> SelfSet whether to generate wrappers for `static`` functions.
Passing
trueto this method will generate a C source file with non-staticfunctions that call thestaticfunctions found in the input headers and can be called from Rust once the source file is compiled.The path of this source file can be set using the
Builder::wrap_static_fns_pathmethod.fn wrap_static_fns_suffix<T: AsRef<str>>(self: Self, suffix: T) -> SelfSet the suffix added to the wrappers for
staticfunctions.This option only comes into effect if
trueis passed to theBuilder::wrap_static_fnsmethod.The default suffix is
__extern.fn wrap_static_fns_path<T: AsRef<Path>>(self: Self, path: T) -> SelfSet the path for the source code file that would be created if any wrapper functions must be generated due to the presence of
staticfunctions.bindgenwill automatically add the right extension to the header and source code files.This option only comes into effect if
trueis passed to theBuilder::wrap_static_fnsmethod.The default path is
temp_dir/bindgen/extern, wheretemp_diris the path returned bystd::env::temp_dir.fn default_visibility(self: Self, visibility: FieldVisibilityKind) -> SelfSet the default visibility of fields, including bitfields and accessor methods for bitfields.
This option only comes into effect if the
Builder::respect_cxx_access_specsoption is disabled.fn clang_macro_fallback(self: Self) -> SelfUse Clang as a fallback for macros that fail to parse using
CExpr.This uses a workaround to evaluate each macro in a temporary file. Because this results in slower compilation, this option is opt-in.
fn clang_macro_fallback_build_dir<P: AsRef<Path>>(self: Self, path: P) -> SelfSet a path to a directory to which
.cand.h.pchfiles should be written for the purpose of using clang to evaluate macros that can't be easily parsed.The default location for
.h.pchfiles is the directory that the corresponding.hfile is located in. The default for the temporary.cfile used for clang parsing is the current working directory. Both of these defaults are overridden by this option.fn generate_deleted_functions(self: Self, doit: bool) -> SelfSet whether to generate C++ functions even marked "=deleted"
Although not useful to call these functions, downstream code generators may need to know whether they've been deleted in order to determine the relocatability of a C++ type (specifically by virtue of which constructors exist.)
fn generate_pure_virtual_functions(self: Self, doit: bool) -> SelfSet whether to generate C++ functions that are pure virtual.
These functions can't be called, so the only reason to generate them is if downstream postprocessors need to know of their existence. This is necessary, for instance, to determine whether a type itself is pure virtual and thus can't be allocated. Downstream code generators may choose to make code to allow types to be allocated but need to avoid doing so if the type contains pure virtual functions.
fn generate_private_functions(self: Self, doit: bool) -> SelfSet whether to generate C++ functions that are private.
These functions can't be called, so the only reason to generate them is if downstream postprocessors need to know of their existence.
impl Builder
fn generate(self: Self) -> Result<Bindings, BindgenError>Generate the Rust bindings using the options built up thus far.
fn dump_preprocessed_input(self: &Self) -> io::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.ior__bindgen.ii
impl Clone for Builder
fn clone(self: &Self) -> Builder
impl Debug for Builder
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl Default for Builder
fn default() -> Builder
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnwindSafe for Builder
impl<T> Any for Builder
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Builder
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Builder
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Builder
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Builder
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Builder
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for Builder
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Builder
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Builder
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>