blob: e77ea0c69ee794ff285d4e50a0957b1effe466e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# Introduction
**[`bindgen`](https://github.com/rust-lang/rust-bindgen) automatically generates Rust
FFI bindings to C and C++ libraries.**
For example, given the C header `cool.h`:
```c
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 the `cool` library's
functions and use its types:
```rust
/* 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);
}
```
|