Struct bindgen::Builder

source ·
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:

  1. constified_enum_module()
  2. bitfield_enum()
  3. newtype_enum()
  4. rustified_enum()

For each C enum, bindgen tries to match the pattern in the following order:

  1. Constified enum module
  2. Bitfield enum
  3. Newtype enum
  4. 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:

  1. clang_arg(): takes a single argument
  2. clang_args(): takes an iterator of arguments
  3. BINDGEN_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, 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§

source§

impl Builder

source

pub fn command_line_flags(&self) -> Vec<String>

Generates the command line flags used to create this Builder.

source

pub fn blocklist_type<T: AsRef<str>>(self, arg: T) -> Builder

Do 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.

source

pub fn blocklist_function<T: AsRef<str>>(self, arg: T) -> Builder

Do 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.

source

pub fn blocklist_item<T: AsRef<str>>(self, arg: T) -> Builder

Do 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.

source

pub fn blocklist_file<T: AsRef<str>>(self, arg: T) -> Builder

Do 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.

source

pub fn blocklist_var<T: AsRef<str>>(self, arg: T) -> Builder

Do 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.

source

pub fn opaque_type<T: AsRef<str>>(self, arg: T) -> Builder

Treat 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.

source

pub fn with_rustfmt<P: Into<PathBuf>>(self, path: P) -> Self

Set an explicit path to the rustfmt binary.

This option only comes into effect if rustfmt is set to be the formatter used by bindgen. Check the documentation of the Builder::formatter method for more information.

source

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.

source

pub fn allowlist_type<T: AsRef<str>>(self, arg: T) -> Builder

Generate bindings for the given type.

This option is transitive by default. Check the documentation of the Builder::allowlist_recursively method for further information.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn allowlist_function<T: AsRef<str>>(self, arg: T) -> Builder

Generate bindings for the given function.

This option is transitive by default. Check the documentation of the Builder::allowlist_recursively method for further information.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn allowlist_var<T: AsRef<str>>(self, arg: T) -> Builder

Generate bindings for the given variable.

This option is transitive by default. Check the documentation of the Builder::allowlist_recursively method for further information.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn allowlist_file<T: AsRef<str>>(self, arg: T) -> Builder

Generate bindings for the content of the given file.

This option is transitive by default. Check the documentation of the Builder::allowlist_recursively method 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.

source

pub fn allowlist_item<T: AsRef<str>>(self, arg: T) -> Builder

Generate 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_recursively method for further information.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn default_enum_style(self, arg: EnumVariation) -> Builder

Set the default style for generated enums.

If this method is not called, the EnumVariation::Consts style will be used by default.

To set the style for individual enums, use Builder::bitfield_enum, Builder::newtype_enum, Builder::newtype_global_enum, Builder::rustified_enum, Builder::rustified_non_exhaustive_enum, Builder::constified_enum_module or Builder::constified_enum.

source

pub fn bitfield_enum<T: AsRef<str>>(self, arg: T) -> Builder

Mark the given enum as being bitfield-like.

This is similar to the Builder::newtype_enum style, but with the bitwise operators implemented.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn newtype_enum<T: AsRef<str>>(self, arg: T) -> Builder

Mark the given enum as a newtype.

This means that an integer newtype will be declared to represent the enum type and its variants will be represented as constants inside of this type’s impl block.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn newtype_global_enum<T: AsRef<str>>(self, arg: T) -> Builder

Mark the given enum as a global newtype.

This is similar to the Builder::newtype_enum style, but the constants for each variant are free constants instead of being declared inside an impl block for the newtype.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn rustified_enum<T: AsRef<str>>(self, arg: T) -> Builder

Mark the given enum as a Rust enum.

This means that each variant of the enum will be represented as a Rust enum variant.

Use this with caution, creating an instance of a Rust enum with an invalid value will cause undefined behaviour. To avoid this, use the Builder::newtype_enum style instead.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn rustified_non_exhaustive_enum<T: AsRef<str>>(self, arg: T) -> Builder

Mark the given enum as a non-exhaustive Rust enum.

This is similar to the Builder::rustified_enum style, but the enum is tagged with the #[non_exhaustive] attribute.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn constified_enum_module<T: AsRef<str>>(self, arg: T) -> Builder

Mark the given enum as 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.

source

pub fn constified_enum<T: AsRef<str>>(self, arg: T) -> Builder

Mark the given enum as a set o integer constants.

This is similar to the Builder::constified_enum_module style, 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.

source

pub fn default_macro_constant_type(self, arg: MacroTypeVariation) -> Builder

Set the default type signedness to be used for macro constants.

If this method is not called, MacroTypeVariation::Unsigned is used by default.

To set the type for individual macro constants, use the ParseCallbacks::int_macro method.

source

pub fn default_alias_style(self, arg: AliasVariation) -> Builder

Set the default style of code generation for typedefs.

If this method is not called, the AliasVariation::TypeAlias style is used by default.

To set the style for individual typedefss, use Builder::type_alias, Builder::new_type_alias or Builder::new_type_alias_deref.

source

pub fn type_alias<T: AsRef<str>>(self, arg: T) -> Builder

Mark the given typedef as a regular Rust type alias.

This is the default behavior, meaning that this method only comes into effect if a style different from AliasVariation::TypeAlias was passed to the Builder::default_alias_style method.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn new_type_alias<T: AsRef<str>>(self, arg: T) -> Builder

Mark the given typedef as a Rust newtype by having the aliased type be wrapped in a struct with #[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.

source

pub fn new_type_alias_deref<T: AsRef<str>>(self, arg: T) -> Builder

Mark the given typedef to be generated as a newtype that can be dereferenced.

This is similar to the Builder::new_type_alias style, but the newtype implements Deref and DerefMut with the aliased type as a target.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn default_non_copy_union_style(self, arg: NonCopyUnionStyle) -> Self

Set the default style of code to generate for unions with non-Copy members.

If this method is not called, the NonCopyUnionStyle::BindgenWrapper style is used by default.

To set the style for individual unions, use Builder::bindgen_wrapper_union or Builder::manually_drop_union.

source

pub fn bindgen_wrapper_union<T: AsRef<str>>(self, arg: T) -> Self

Mark the given union to use a bindgen-generated wrapper for its members if at least one them is not Copy.

This is the default behavior, meaning that this method only comes into effect if a style different from NonCopyUnionStyle::BindgenWrapper was passed to the Builder::default_non_copy_union_style method.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn manually_drop_union<T: AsRef<str>>(self, arg: T) -> Self

Mark the given union to use ::core::mem::ManuallyDrop for its members if at least one of them is not Copy.

The ManuallyDrop type 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.

source

pub fn emit_builtins(self) -> Builder

Generate Rust bindings for built-in definitions (for example __builtin_va_list).

Bindings for built-in definitions are not emitted by default.

source

pub fn emit_clang_ast(self) -> Builder

Emit the Clang AST to stdout for debugging purposes.

The Clang AST is not emitted by default.

source

pub fn emit_ir(self) -> Builder

Emit the bindgen internal representation to stdout for debugging purposes.

This internal representation is not emitted by default.

source

pub fn emit_ir_graphviz<T: Into<String>>(self, path: T) -> Builder

Set the path for the file where thebindgen internal representation will be emitted as a graph using the graphviz DOT language.

This graph representation is not emitted by default.

source

pub fn enable_cxx_namespaces(self) -> Builder

Emulate C++ namespaces using Rust modules in the generated bindings.

C++ namespaces are not emulated by default.

source

pub fn enable_function_attribute_detection(self) -> Self

Enable 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.

source

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 does not change the names used for allowlisting and blocklisting, which should still be mangled with the namespaces. Additionally, this option may cause bindgen to generate duplicate names.

source

pub fn disable_nested_struct_naming(self) -> Builder

Disable nested struct naming.

The following structs have different names for C and C++. In C, they are visible as foo and bar. In C++, they are visible as foo and foo::bar.

struct foo {
    struct bar {
    } b;
};

bindgen tries to avoid duplicate names by default, so it follows the C++ naming convention and it generates foo and foo_bar instead of just foo and bar.

This method disables this behavior and it is indented to be used only for headers that were written in C.

source

pub fn disable_header_comment(self) -> Self

Do not insert the bindgen version identifier into the generated bindings.

This identifier is inserted by default.

source

pub fn layout_tests(self, doit: bool) -> Self

Set whether layout tests should be generated.

Layout tests are generated by default.

source

pub fn impl_debug(self, doit: bool) -> Self

Set whether Debug should be implemented for types that cannot derive it.

This option is disabled by default.

source

pub fn impl_partialeq(self, doit: bool) -> Self

Set whether PartialEq should be implemented for types that cannot derive it.

This option is disabled by default.

source

pub fn derive_copy(self, doit: bool) -> Self

Set whether the Copy trait should be derived when possible.

Copy is derived by default.

source

pub fn derive_debug(self, doit: bool) -> Self

Set whether the Debug trait should be derived when possible.

The Builder::impl_debug method can be used to implement Debug for types that cannot derive it.

Debug is derived by default.

source

pub fn derive_default(self, doit: bool) -> Self

Set whether the Default trait should be derived when possible.

Default is not derived by default.

source

pub fn derive_hash(self, doit: bool) -> Self

Set whether the Hash trait should be derived when possible.

Hash is not derived by default.

source

pub fn derive_partialord(self, doit: bool) -> Self

Set whether the PartialOrd trait should be derived when possible.

Take into account that Ord cannot be derived for a type that does not implement PartialOrd. For this reason, setting this method to false also sets automatically Builder::derive_ord to false.

PartialOrd is not derived by default.

source

pub fn derive_ord(self, doit: bool) -> Self

Set whether the Ord trait should be derived when possible.

Take into account that Ord cannot be derived for a type that does not implement PartialOrd. For this reason, the value set with this method will also be set automatically for Builder::derive_partialord.

Ord is not derived by default.

source

pub fn derive_partialeq(self, doit: bool) -> Self

Set whether the PartialEq trait should be derived when possible.

Take into account that Eq cannot be derived for a type that does not implement PartialEq. For this reason, setting this method to false also sets automatically Builder::derive_eq to false.

The Builder::impl_partialeq method can be used to implement PartialEq for types that cannot derive it.

PartialEq is not derived by default.

source

pub fn derive_eq(self, doit: bool) -> Self

Set whether the Eq trait should be derived when possible.

Take into account that Eq cannot be derived for a type that does not implement PartialEq. For this reason, the value set with this method will also be set automatically for Builder::derive_partialeq.

Eq is not derived by default.

source

pub fn use_core(self) -> Builder

Use core instead of std in the generated bindings.

std is used by default.

source

pub fn ctypes_prefix<T: Into<String>>(self, prefix: T) -> Builder

Use the given prefix for the C platform-specific types instead of ::std::os::raw.

Alternatively, the Builder::use_core method can be used to set the prefix to ::core::ffi or ::core::os::raw.

source

pub fn anon_fields_prefix<T: Into<String>>(self, prefix: T) -> Builder

Use 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:

struct integer {
  struct {
    int inner;
  };
}

The only field of the integer struct is an anonymous field and its Rust representation will be named using this prefix followed by an integer identifier.

The default prefix is __bindgen_anon_.

source

pub fn time_phases(self, doit: bool) -> Self

Set whether to measure the elapsed time for each one of the bindgen phases. This information is printed to stderr.

The elapsed time is not measured by default.

source

pub fn no_convert_floats(self) -> Self

Avoid converting C float types to f32 and f64.

source

pub fn raw_line<T: Into<String>>(self, arg: T) -> Self

Add a line of Rust code at the beginning of the generated bindings. The string is passed through without any modification.

source

pub fn module_raw_line<T, U>(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_namespaces method is also being called.

source

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 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();
source

pub fn clang_arg<T: Into<String>>(self, arg: T) -> Builder

Add an argument to be passed straight through to Clang.

source

pub fn clang_args<I: IntoIterator>(self, args: I) -> Builder
where I::Item: AsRef<str>,

Add several arguments to be passed straight through to Clang.

source

pub fn header_contents(self, name: &str, contents: &str) -> Builder

Add contents as an input C/C++ header named name.

This can be used to inject additional C/C++ code as an input without having to create additional header files.

source

pub fn parse_callbacks(self, cb: Box<dyn ParseCallbacks>) -> Self

Add a new ParseCallbacks instance to configure types in different situations.

source

pub fn ignore_functions(self) -> Builder

Do not generate any functions.

Functions are generated by default.

source

pub fn ignore_methods(self) -> Builder

Do not generate any methods.

Methods are generated by default.

source

pub fn with_codegen_config(self, config: CodegenConfig) -> Self

Choose what to generate using a CodegenConfig.

This option overlaps with Builder::ignore_functions and Builder::ignore_methods.

All the items in CodegenConfig are generated by default.

source

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 do not 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 using bindgen becomes a bit more difficult, because you cannot reference paths like std::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.

source

pub fn generate_comments(self, doit: bool) -> Self

Set 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 the Builder::clang_arg method 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.

source

pub fn generate_inline_functions(self, doit: bool) -> Self

Set whether to generate inline functions.

This option is disabled by default.

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. Check the Builder::wrap_static_fns method for an alternative.

source

pub fn allowlist_recursively(self, doit: bool) -> Self

Set whether to recursively allowlist items.

Items are allowlisted recursively by default.

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 type that it transitively references. If false is passed to this method, bindgen will not emit bindings for anything except the explicitly allowlisted items, meaning that the definition for MoonBoots would not be generated. 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 missing definitions is by using the Builder::raw_line method, another would be to define them in Rust and then include!(...) the bindings immediately afterwards.

source

pub fn objc_extern_crate(self, doit: bool) -> Self

Emit #[macro_use] extern crate objc; instead of use objc; in the prologue of the files generated from objective-c files.

use objc; is emitted by default.

source

pub fn generate_block(self, doit: bool) -> Self

Generate proper block signatures instead of void pointers.

void pointers are used by default.

source

pub fn generate_cstr(self, doit: bool) -> Self

Set whether string constants should be generated as &CStr instead 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_unchecked in const contexts is needed.

This option is disabled by default but will become enabled by default in a future release, so enabling this is recommended.

source

pub fn block_extern_crate(self, doit: bool) -> Self

Emit #[macro_use] extern crate block; instead of use block; in the prologue of the files generated from apple block files.

use block; is emitted by default.

source

pub fn trust_clang_mangling(self, doit: bool) -> Self

Set 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 libclang versions seem to return incorrect results in some cases for non-mangled functions, check #528 for more information.

source

pub fn detect_include_paths(self, doit: bool) -> Self

Set whether to detect include paths using clang_sys.

clang_sys is used to detect include paths by default.

source

pub fn fit_macro_constants(self, doit: bool) -> Self

Set whether bindgen should try to fit macro constants into types smaller than u32 and i32.

This option is disabled by default.

source

pub fn prepend_enum_name(self, doit: bool) -> Self

Set whether to prepend the enum name to constant or newtype variants.

The enum name is prepended by default.

source

pub fn rust_target(self, rust_target: RustTarget) -> Self

Specify the Rust target version.

The default target is the latest stable Rust version.

source

pub fn disable_untagged_union(self) -> Self

Disable support for native Rust unions, if supported.

The default value of this option is set based on the value passed to Builder::rust_target.

source

pub fn record_matches(self, doit: bool) -> Self

Set whether we should record which items in our regex sets did match any C items.

Matches are recorded by default.

source

pub fn size_t_is_usize(self, is: bool) -> Self

Set whether size_t should be translated to usize.

If size_t is translated to usize, type definitions for size_t will not be emitted.

size_t is translated to usize by default.

source

pub fn rustfmt_bindings(self, doit: bool) -> Self

👎Deprecated

Set whether rustfmt should be used to format the generated bindings.

rustfmt is used by default.

This method overlaps in functionality with the more general Builder::formatter. Thus, the latter should be preferred.

source

pub fn formatter(self, formatter: Formatter) -> Self

Set which tool should be used to format the generated bindings.

The default formatter is Formatter::Rustfmt.

To be able to use prettyplease as a formatter, the "prettyplease" feature for bindgen must be enabled in the Cargo manifest.

source

pub fn rustfmt_configuration_file(self, path: Option<PathBuf>) -> Self

Set the absolute path to the rustfmt configuration file.

The default rustfmt options are used if None is passed to this method or if this method is not called at all.

Calling this method will set the Builder::rustfmt_bindings option to true and the Builder::formatter option to Formatter::Rustfmt.

source

pub fn no_partialeq<T: Into<String>>(self, arg: T) -> Builder

Do not derive PartialEq for a given type.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn no_copy<T: Into<String>>(self, arg: T) -> Self

Do not derive Copy and Clone for a given type.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn no_debug<T: Into<String>>(self, arg: T) -> Self

Do not derive Debug for a given type.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn no_default<T: Into<String>>(self, arg: T) -> Self

Do not derive or implement Default for a given type.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn no_hash<T: Into<String>>(self, arg: T) -> Builder

Do not derive Hash for a given type.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn must_use_type<T: Into<String>>(self, arg: T) -> Builder

Annotate 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.

source

pub fn array_pointers_in_arguments(self, doit: bool) -> Self

Translate arrays T arr[size] into array pointers *mut [T; size] instead of translating them as *mut T which is the default.

The same is done for *const pointers.

source

pub fn wasm_import_module_name<T: Into<String>>(self, import_name: T) -> Self

Adds the #[link(wasm_import_module = import_name)] attribute to all the extern blocks generated by bindgen.

This attribute is not added by default.

source

pub fn dynamic_library_name<T: Into<String>>( self, dynamic_library_name: T ) -> Self

Generate bindings for a shared library with the given name.

This option is disabled by default.

Set 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_name option is set.

This option is disabled by default.

source

pub fn respect_cxx_access_specs(self, doit: bool) -> Self

Set whether to respect the C++ access specifications.

Passing true to this method will set the visibility of the generated Rust items as pub only if the corresponding C++ items are publicly accessible instead of marking all the items as public, which is the default.

source

pub fn translate_enum_integer_types(self, doit: bool) -> Self

Set whether to always translate enum integer types to native Rust integer types.

Passing true to this method will result in enums having types such as u32 and i16 instead of c_uint and c_short which is the default. The #[repr] types of Rust enums are always translated to Rust integer types.

source

pub fn c_naming(self, doit: bool) -> Self

Set whether to generate types with C style naming.

Passing true to this method will add prefixes to the generated type names. For example, instead of a struct with name A we will generate a struct with struct_A. Currently applies to structs, unions, and enums.

source

pub fn explicit_padding(self, doit: bool) -> Self

Set whether to always emit explicit padding fields.

This option should be enabled if a struct needs to be serialized in its native format (padding bytes and all). This could be required if such struct will 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.

source

pub fn vtable_generation(self, doit: bool) -> Self

Set 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.

source

pub fn sort_semantically(self, doit: bool) -> Self

Set whether to sort the generated Rust items in a predefined manner.

Items are not ordered by default.

source

pub fn merge_extern_blocks(self, doit: bool) -> Self

Merge all extern blocks under the same module into a single one.

Extern blocks are not merged by default.

source

pub fn wrap_unsafe_ops(self, doit: bool) -> Self

Wrap all unsafe operations in unsafe blocks.

Unsafe operations are not wrapped by default.

source

pub fn override_abi<T: Into<String>>(self, abi: Abi, arg: T) -> Self

Override the ABI of a given function.

Regular expressions are supported. Check the regular expression arguments section and the regex crate documentation for further information.

source

pub fn wrap_static_fns(self, doit: bool) -> Self

Set whether to generate wrappers for `static`` functions.

Passing true to this method will generate a C source file with non-static functions that call the static functions 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_path method.

source

pub fn wrap_static_fns_suffix<T: AsRef<str>>(self, suffix: T) -> Self

Set the suffix added to the wrappers for static functions.

This option only comes into effect if true is passed to the Builder::wrap_static_fns method.

The default suffix is __extern.

source

pub fn wrap_static_fns_path<T: AsRef<Path>>(self, path: T) -> Self

Set the path for the source code file that would be created if any wrapper functions must be generated due to the presence of static functions.

bindgen will automatically add the right extension to the header and source code files.

This option only comes into effect if true is passed to the Builder::wrap_static_fns method.

The default path is temp_dir/bindgen/extern, where temp_dir is the path returned by std::env::temp_dir .

source

pub fn default_visibility(self, visibility: FieldVisibilityKind) -> Self

Set the default visibility of fields, including bitfields and accessor methods for bitfields.

This option only comes into effect if the Builder::respect_cxx_access_specs option is disabled.

source

pub fn emit_diagnostics(self) -> Self

Emit diagnostics.

These diagnostics are emitted to stderr if you are using bindgen-cli or printed using cargo:warning= if you are using bindgen as a build-dependency.

Diagnostics are not emitted by default.

The layout and contents of these diagnostic messages are not covered by versioning and can change without notice.

source§

impl Builder

source

pub fn generate(self) -> Result<Bindings, BindgenError>

Generate the Rust bindings using the options built up thus far.

source

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

Trait Implementations§

source§

impl Clone for Builder

source§

fn clone(&self) -> Builder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Builder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Builder

source§

fn default() -> Builder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.