pub struct Bindgen { /* private fields */ }Expand description
Implementations§
Source§impl Bindgen
impl Bindgen
Sourcepub fn input(&mut self, input: impl AsRef<Path>) -> &mut Self
pub fn input(&mut self, input: impl AsRef<Path>) -> &mut Self
Adds a .winmd file or directory.
Explicit inputs replace the bundled metadata. Call Bindgen::input_default to include
the bundled metadata alongside them.
Sourcepub fn input_default(&mut self) -> &mut Self
pub fn input_default(&mut self) -> &mut Self
Adds the default Windows metadata.
Included automatically when no explicit inputs are supplied.
Sourcepub fn input_bytes(&mut self, input: &[u8]) -> &mut Self
pub fn input_bytes(&mut self, input: &[u8]) -> &mut Self
Adds a .winmd file from memory.
Uses the same default metadata behavior as Bindgen::input.
Sourcepub fn input_byte_sets<I, B>(&mut self, inputs: I) -> &mut Self
pub fn input_byte_sets<I, B>(&mut self, inputs: I) -> &mut Self
Adds .winmd files from memory.
Sourcepub fn output(&mut self, output: impl AsRef<Path>) -> &mut Self
pub fn output(&mut self, output: impl AsRef<Path>) -> &mut Self
Sets the generated Rust file.
Defaults to bindings.rs in the runtime OUT_DIR directory. An explicit path is required
when OUT_DIR is unset or empty, and always when generating a package.
Sourcepub fn filter(&mut self, filter: &str) -> &mut Self
pub fn filter(&mut self, filter: &str) -> &mut Self
Adds a filter rule to include or exclude APIs.
See the crate documentation for an example table. The same syntax applies to
Bindgen::filters, Bindgen::filter_file, and bindgen’s --filter arguments.
§Names and groups
Select a function, constant, type, or namespace. Bare names match across namespaces;
qualify a name to restrict it to one namespace. Dots and :: both separate path segments.
Namespace selections include descendant namespaces. The bundled Win32 metadata uses
Windows.Win32, not the subsystem namespaces used by the umbrella crates’ Cargo features.
Groups abbreviate separate selections and may nest: Windows::Foundation::{Uri, AsyncStatus}.
Trailing commas are allowed. * wildcards are not supported.
§Members and dependencies
A bare type selects all its members. Use Type::Member or Type::{Member, OtherMember}
for a subset. Members may be methods, properties, events, or enum variants.
Use native member or overload names, not renamed Rust methods. Property and event names
select their accessor pairs; requesting an event’s add_ method also selects its remove_
method. Class::CreateInstance selects a WinRT class’s default constructor.
Signature dependencies are included automatically, but interfaces reached only through
signatures can be name-only declarations. Select their methods explicitly to call them.
Type::{} requests the type without requesting its methods or enum variants; it does not
remove methods selected elsewhere. In minimal mode, a COM interface selected this way can
use Bindgen::implement to emit its implementation trait and vtable without caller wrappers.
§Combining rules
Prefix a selection with ! to exclude it. More specific type/namespace rules take precedence;
exclusions win ties regardless of argument order. Member and enum-variant selections narrow
whole-type selections, also regardless of order. Excluded members and variants win over
included ones, except that implementation traits require the interface’s complete method ABI.
Named Bindgen::implement selectors reject method-level inclusions or exclusions on matching
interfaces. Select the whole interface or use Interface::{} instead.
Bindgen::implement_all allows member filters, but emits the complete method ABI for
implemented interfaces.
Chained members (Type::Read::Write), trailing separators (Type::), and empty entries
inside a group (Type::{Read,,Write}) are rejected. Use Type::{Read, Write} for several
members or Type::{} for a name-only selection.
Sourcepub fn filter_file(&mut self, input: impl AsRef<Path>) -> &mut Self
pub fn filter_file(&mut self, input: impl AsRef<Path>) -> &mut Self
Adds filter rules from a text file.
Uses Bindgen::filter syntax, with whitespace separating filters outside groups.
Groups may span lines. Lines beginning with // after optional whitespace are comments;
inline comments require a separate // token followed by whitespace or the end of the line.
Sourcepub fn filter_files<I, S>(&mut self, inputs: I) -> &mut Self
pub fn filter_files<I, S>(&mut self, inputs: I) -> &mut Self
Adds filter rules from text files.
Sourcepub fn filters<I, S>(&mut self, filters: I) -> &mut Self
pub fn filters<I, S>(&mut self, filters: I) -> &mut Self
Add multiple filter rules to include or exclude APIs.
Uses the same syntax as Bindgen::filter.
Sourcepub fn derive(&mut self, derive: &str) -> &mut Self
pub fn derive(&mut self, derive: &str) -> &mut Self
Specifies extra derives as Type=Trait,OtherTrait, for example SYSTEMTIME=Debug.
The type may be a bare or dotted qualified name and must be included in the generated bindings. Later entries for the same type replace earlier lists.
Sourcepub fn derives<I, S>(&mut self, derives: I) -> &mut Self
pub fn derives<I, S>(&mut self, derives: I) -> &mut Self
Specifies extra derives for multiple types, using the syntax of Bindgen::derive.
Sourcepub fn rustfmt(&mut self, rustfmt: &str) -> &mut Self
pub fn rustfmt(&mut self, rustfmt: &str) -> &mut Self
Set comma-separated rustfmt configuration options, such as max_width=120.
These are passed to rustfmt --config, not used as an executable path.
The default is newline_style=Unix; supplied options override matching defaults.
Formatting is best effort: failures leave the output unformatted without a warning.
Sourcepub fn modules(&mut self) -> &mut Self
pub fn modules(&mut self) -> &mut Self
Nest items in one Rust module per metadata namespace instead of a single flat list.
Use this when the selected APIs define the same name in more than one namespace.
Sourcepub fn package(&mut self) -> &mut Self
pub fn package(&mut self) -> &mut Self
Generate bindings as a package with one file per namespace.
Sourcepub fn implement_all(&mut self) -> &mut Self
pub fn implement_all(&mut self) -> &mut Self
Includes implementation traits for every native and WinRT interface in scope.
Unlike Bindgen::implement, allows method-level filters. Implemented interfaces still
emit their complete method ABI.
Sourcepub fn implement(&mut self, name: &str) -> &mut Self
pub fn implement(&mut self, name: &str) -> &mut Self
Includes implementation traits for a native or WinRT interface or namespace prefix.
Use a dotted qualified name (Windows.Win32.ISequentialStream) or a namespace prefix.
Unlike filters, bare interface names are not resolved. The interface must be included in
the generated bindings, directly or as a dependency; this does not select it.
Required base interface implementations are included unless excluded or supplied by a
referenced crate.
Method-level inclusions or exclusions on matching interfaces or their required bases cause
Bindgen::write to panic. Select the whole interface or use Interface::{} instead.
Sourcepub fn implements<I, S>(&mut self, names: I) -> &mut Self
pub fn implements<I, S>(&mut self, names: I) -> &mut Self
Includes implementation traits for multiple native or WinRT interfaces or namespace prefixes.
Sourcepub fn compose(&mut self, name: &str) -> &mut Self
pub fn compose(&mut self, name: &str) -> &mut Self
Selects a composable WinRT class as a composition target.
The class and its composable factory methods must also be selected by a filter.
Sourcepub fn composes<I, S>(&mut self, names: I) -> &mut Self
pub fn composes<I, S>(&mut self, names: I) -> &mut Self
Selects multiple composable WinRT classes as composition targets.
Sourcepub fn sys(&mut self) -> &mut Self
pub fn sys(&mut self) -> &mut Self
Generate raw or sys-style Rust bindings using windows-link.
Mutually exclusive with Bindgen::full.
Sourcepub fn full(&mut self) -> &mut Self
pub fn full(&mut self) -> &mut Self
Generate full-fidelity Rust bindings.
Adds per-class wrapper methods, inherited interface forwarders, handle ergonomics,
free-function wrappers, and implementation traits for interfaces not marked ExclusiveTo.
Use Bindgen::implement or Bindgen::implement_all for ExclusiveTo interfaces; an
explicit selection replaces the full-mode default.
Mutually exclusive with Bindgen::sys.
Sourcepub fn extern_fns(&mut self) -> &mut Self
pub fn extern_fns(&mut self) -> &mut Self
Generate extern declarations rather than link! macros in any binding style.
DLL and entry-point selection are left to the caller’s import libraries, including ordinals.
Sourcepub fn dead_code(&mut self) -> &mut Self
pub fn dead_code(&mut self) -> &mut Self
Use pub(crate) where possible to surface unused bindings as dead-code warnings.
Interface and vtable types remain public for trait implementations.
Sourcepub fn write(&self)
pub fn write(&self)
Generate the bindings.
Without an explicit output, writes OUT_DIR/bindings.rs. Use distinct explicit paths for
multiple output files. Does not emit Cargo dependency-tracking directives.
Resolves declarations on demand, including dependencies of selected APIs. Errors in unused declarations may not be reported.
Panics if input processing, code generation, or writing the output fails.