Struct ispc::bindgen::Builder

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§

§

impl Builder

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

Generates the command line flags used to create this Builder.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

pub fn depfile<H, D>(self, output_module: H, depfile: D) -> Builder
where H: Into<String>, D: Into<PathBuf>,

Add a depfile output which will be written alongside the generated bindings.

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

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.

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

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.

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

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.

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

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.

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

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.

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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.

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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.

pub fn emit_clang_ast(self) -> Builder

Emit the Clang AST to stdout for debugging purposes.

The Clang AST is not emitted by default.

pub fn emit_ir(self) -> Builder

Emit the bindgen internal representation to stdout for debugging purposes.

This internal representation is not emitted by default.

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

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.

pub fn enable_cxx_namespaces(self) -> Builder

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

C++ namespaces are not emulated by default.

pub fn enable_function_attribute_detection(self) -> Builder

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.

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.

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.

pub fn disable_header_comment(self) -> Builder

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

This identifier is inserted by default.

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

Set whether layout tests should be generated.

Layout tests are generated by default.

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

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

This option is disabled by default.

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

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

This option is disabled by default.

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

Set whether the Copy trait should be derived when possible.

Copy is derived by default.

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

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.

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

Set whether the Default trait should be derived when possible.

Default is not derived by default.

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

Set whether the Hash trait should be derived when possible.

Hash is not derived by default.

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

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.

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

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.

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

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.

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

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.

pub fn use_core(self) -> Builder

Use core instead of std in the generated bindings.

std is used by default.

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

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.

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

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

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

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.

pub fn no_convert_floats(self) -> Builder

Avoid converting C float types to f32 and f64.

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

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

pub fn module_raw_line<T, U>(self, module: T, line: U) -> Builder
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.

pub fn header<T>(self, header: T) -> Builder
where T: Into<String>,

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

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

Add an argument to be passed straight through to Clang.

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

Add several arguments to be passed straight through to Clang.

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.

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

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

pub fn ignore_functions(self) -> Builder

Do not generate any functions.

Functions are generated by default.

pub fn ignore_methods(self) -> Builder

Do not generate any methods.

Methods are generated by default.

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

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.

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.

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

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.

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

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.

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

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.

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

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.

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

Generate proper block signatures instead of void pointers.

void pointers are used by default.

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

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.

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

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.

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

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.

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

Set whether to detect include paths using clang_sys.

clang_sys is used to detect include paths by default.

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

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

This option is disabled by default.

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

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

The enum name is prepended by default.

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

Specify the Rust target version.

The default target is the latest stable Rust version.

pub fn disable_untagged_union(self) -> Builder

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.

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

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

Matches are recorded by default.

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

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.

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

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

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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

This attribute is not added by default.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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

Items are not ordered by default.

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

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

Extern blocks are not merged by default.

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

Wrap all unsafe operations in unsafe blocks.

Unsafe operations are not wrapped by default.

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

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.

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

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.

§

impl Builder

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

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

pub fn dump_preprocessed_input(&self) -> Result<(), Error>

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§

§

impl Clone for Builder

§

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
§

impl Debug for Builder

§

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

Formats the value using the given formatter. Read more
§

impl Default for Builder

§

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.