Generate traits from C header files.
When rewriting a C libary in Rust, you often want to preserve the original C header files.
This is possible using this crate in conjuction with bindgen.
Take the following C header.
typedef struct yakshaver yakshaver;
/** create a yakshaver */
yakshaver *;
/** destroy a yakshaver */
void ;
/** get number of yaks shaved */
unsigned int ;
/** shave some yaks */
int ;
In your build.rs script:
- Use
bindgento generate equivalent Rust blocks. - Use [
seesaw] to generate a trait from those bindings.
// build.rs
The generated file will look like this:
/* this file is @generated by seesaw */
And you can export the same ABI as the C library using [no_mangle],
which simply adds #[no_mangle] to each of the functions.