Introduction
bindgen
automatically generates RustFFI bindings to C and C++ libraries.
For example, given the C headercool.h
:
typedef struct CoolStruct { int x; int y;} CoolStruct;void cool_function(int i, char c, CoolStruct* cs);
bindgen
produces Rust FFI code allowing you to call into thecool
library'sfunctions and use its types:
#![allow(unused)]fn main() {/* automatically generated by rust-bindgen 0.99.9 */#[repr(C)]pub struct CoolStruct { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int,}extern "C" { pub fn cool_function(i: ::std::os::raw::c_int, c: ::std::os::raw::c_char, cs: *mut CoolStruct);}}