liveBook · Manning

Binding

As explained in Embedded Software with Rust

A declaration describing a foreign-language function or data type so code in another language can interact with it.

A binding declares foreign functions and data types so code in another language can use them. In Rust–C integration, bindgen generates Rust FFI declarations from C headers; cbindgen generates C headers from Rust code. section 8.5 section 8.5.1

For embedded Rust, bindgen options help control generated declarations:

  • --use-core selects Rust’s core library and maps C types to core::ffi types. section 8.5.1
  • Allowlist options restrict generation to selected names; blocklist options exclude names that should not be generated. section 8.5.1
  • Arguments after -- are passed to libclang, including the target used to parse the C header. section 8.5.1
bindgen example.h \
  --use-core \
  --allowlist-type "ExampleStruct" \
  --allowlist-function "process_example" \
  --blocklist-function "strcpy" \
  --blocklist-var "errno" \
  -o example_bindings.rs \
  -- -target thumbv7em-none-eabi

This command generates Rust bindings for selected declarations, excludes named items, writes an output file, and passes an embedded target to libclang. section 8.5.1

How Embedded Software with Rust covers it

How deep it goes
Shows header parsing, declaration filtering, core-based output, and target selection through a command-line workflow.
Examples
Uses a hardware-abstraction header declaring ExampleStruct and process_example, with a thumbv7em-none-eabi generation command.
What you can do after
Apply it via bindgen to generate selected Rust FFI declarations from C headers for an embedded target.
How it connects
Links bindings to Rust FFI, C headers, bindgen, cbindgen, and no_std integration.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Embedded Software with Rust. The section links point to the parts of the book it draws on.