expression
Generate a C header for Rust exports
Cbindgen travels in the opposite direction from bindgen: it emits C or C++ declarations from Rust source. The exported Rust function uses a C ABI, a deliberately unique symbol and fixed-width integer types. Header generation does not compile or link the library; a native client must use the generated header and matching shared library. Expected lab stdout (not executed): 42 Common mistake: Assuming a generated header makes Rust-specific types ABI-stable. This is part of a multi-file lab, not a standalone playground snippet.
Formal Syntax & Structure
rust syntaxrust
cbindgen --config cbindgen.toml --crate bm106-export --output bm106_export.hWorking Example
Example Snippetrust
// SAFETY: this unique exported symbol is reserved by the library ABI.#[unsafe(no_mangle)]pub extern "C" fn bm106_double(input: u16) -> u32 { u32::from(input) * 2}