Skip to main content

Bindgen

Struct Bindgen 

Source
pub struct Bindgen { /* private fields */ }
Expand description

Builder for generating Windows API bindings.

This is the fluent alternative to bindgen.

§Example

windows_bindgen::Bindgen::new()
    .output("src/bindings.rs")
    .filter("GetTickCount")
    .write();

Implementations§

Source§

impl Bindgen

Source

pub fn new() -> Self

Creates a new builder with default options.

Source

pub fn input(&mut self, input: impl AsRef<Path>) -> &mut Self

Adds a .winmd file or directory.

Source

pub fn input_default(&mut self) -> &mut Self

Adds the default Windows metadata.

Source

pub fn input_bytes(&mut self, input: &[u8]) -> &mut Self

Adds a .winmd file from memory.

Source

pub fn input_byte_sets<I, B>(&mut self, inputs: I) -> &mut Self
where I: IntoIterator<Item = B>, B: AsRef<[u8]>,

Adds .winmd files from memory.

Source

pub fn inputs<I, S>(&mut self, inputs: I) -> &mut Self
where I: IntoIterator<Item = S>, S: AsRef<Path>,

Adds .winmd files or directories.

Source

pub fn output(&mut self, output: impl AsRef<Path>) -> &mut Self

Sets the generated Rust file.

Source

pub fn filter(&mut self, filter: &str) -> &mut Self

Add a filter rule to include or exclude APIs.

Filter rules may be a function or type name, a namespace prefix, a fully-qualified name, or a method-level entry of the form Namespace.Type::Method (with optional Property / Event sugar). Prefix with ! to exclude rather than include. See the crate-level docs for the full grammar.

Source

pub fn filter_file(&mut self, input: impl AsRef<Path>) -> &mut Self

Adds filter rules from a text file.

Source

pub fn filter_files<I, S>(&mut self, inputs: I) -> &mut Self
where I: IntoIterator<Item = S>, S: AsRef<Path>,

Adds filter rules from text files.

Source

pub fn filters<I, S>(&mut self, filters: I) -> &mut Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

Add multiple filter rules to include or exclude APIs.

Filter rules may be a function or type name, a namespace prefix, a fully-qualified name, or a method-level entry of the form Namespace.Type::Method (with optional Property / Event sugar). Prefix with ! to exclude rather than include. See the crate-level docs for the full grammar.

Source

pub fn derive(&mut self, derive: &str) -> &mut Self

Add an extra trait for types to derive.

Source

pub fn derives<I, S>(&mut self, derives: I) -> &mut Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

Add multiple extra traits for types to derive.

Source

pub fn rustfmt(&mut self, rustfmt: &str) -> &mut Self

Override the default Rust formatter path.

Source

pub fn flat(&mut self) -> &mut Self

Avoid the default namespace-to-module conversion.

Source

pub fn package(&mut self) -> &mut Self

Generate bindings as a package with one file per namespace.

Source

pub fn package_feature_root(&mut self, namespace: &str) -> &mut Self

Treats the given top-level package namespace as a feature-only root whose child namespaces depend directly on one another.

Source

pub fn external_reference( &mut self, filter: &str, rust_path_prefix: &str, style: ReferenceStyle, ) -> &mut Self

Routes metadata types matched by filter to an external Rust crate or module prefix.

The filter uses the same namespace and type syntax as Bindgen::filter. Routed types remain available as dependencies of generated APIs, but are not generated in this output package or represented by local Cargo feature gates. style controls whether the full metadata namespace, its root-stripped form, or no namespace is appended to the Rust path.

builder.external_reference(
    "Vendor.Types",
    "vendor_bindings",
    windows_bindgen::ReferenceStyle::Full,
);
Source

pub fn reference( &mut self, rust_path_prefix: &str, style: ReferenceStyle, filter: &str, ) -> &mut Self

Maps referenced metadata to a Rust crate or module prefix.

Unlike Bindgen::external_reference, an explicitly selected local type takes precedence over this reference. This matches the historical --reference behavior.

Source

pub fn implement_all(&mut self) -> &mut Self

Includes implementation traits for every WinRT interface in scope.

Source

pub fn implement(&mut self, name: &str) -> &mut Self

Includes implementation traits for a WinRT interface or namespace prefix.

The name may be a fully-qualified type name (Namespace.Name) or a namespace prefix that matches every type defined under it.

Source

pub fn implements<I, S>(&mut self, names: I) -> &mut Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

Includes implementation traits for multiple WinRT interfaces or namespace prefixes.

Source

pub fn compose(&mut self, name: &str) -> &mut Self

Selects a composable WinRT class as a minimal-mode composition target.

The class and its composable factory methods must also be selected by a filter.

Source

pub fn composes<I, S>(&mut self, names: I) -> &mut Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

Selects multiple composable WinRT classes as minimal-mode composition targets.

Source

pub fn sys(&mut self) -> &mut Self

Generate raw or sys-style Rust bindings.

Mutually exclusive with Bindgen::minimal; panics if minimal was already selected.

Source

pub fn minimal(&mut self) -> &mut Self

Generate minimal-mode Rust bindings.

Drops per-class wrapper methods, inherited interface forwarders, handle ergonomics, and free-function wrappers.

Mutually exclusive with --sys.

Source

pub fn extern_fns(&mut self) -> &mut Self

Generate extern declarations rather than link! macros for sys-style Rust bindings.

Only valid in combination with Bindgen::sys; panics otherwise.

Source

pub fn dead_code(&mut self) -> &mut Self

Emit pub(crate) instead of pub on generated items to surface unused bindings as dead-code warnings.

Source

pub fn write(&self)

Generate the bindings.

Trait Implementations§

Source§

impl Default for Bindgen

Source§

fn default() -> Self

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

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.