Reexport auto-generated FFI functions by macros

I’m writing a binding for a C library with help of rust-bindgen for which the function signatures are generated automatically into a bindings.rs as:

#[repr(C)]
struct A {
  ...
}

struct B {
  ...
}

extern "C" {
  pub fn foo(x: *mut A, y: *mut B);
  ...
}

I’m not very happy with this signature of foo because, for example, I know that x is a pointer to a constant struct. Moreover, I want to apply the idea of @Yandros to improve the signature into something likes

extern "C" {
  pub fn foo(x: &'_ A, y: &'_ mut B);
}

so that means the original automatically generated foo should be private, while the rexport foo is public.

But binding.rs has a bunch of such a function foo, and re-export by rewriting them by hand is a very time consuming task. I think that macros (but I’m not sure) should help, for example there might exist one (or several) magic macro rewrite!


// hide
mod ffi {
   include!("binding.rs); // so bunch of functions: foo, bar
}

// re-exports
exterrn "C" {
  rewrite!(foo); // should expand to: pub fn foo(x: &'_A, y: &'_ mut B)
  rewrite!(bar);
}

Many thanks for any help.