-
Notifications
You must be signed in to change notification settings - Fork 360
Description
Hello! I hope you are doing well.
Love cbindgen! Phenomenal work that you all have accomplished.
I'm reaching out because I'm looking for very particular code generation behavior. I wanted to know if this is something that cbindgen can already do, is planning to do, or is explicitly not going to be supported.
Suppose that I'm trying to replace C++ code class-by-class in an existing codebase. Suppose also that the class definition is very simple and looks like this:
Click to view original C++ code
class FooBar {
public:
using my_foo_t = uint32_t;
FooBar(my_foo_t my_foo) : m_favorite_foo(my_foo) {}
bool is_favorite_foo(const FooBar& foo_under_test) {
return foo_under_test == m_favorite_foo;
}
private:
my_foo_t m_favorite_foo;
}To port this class, I'd write something like following Rust code:
Click to view Rust port
pub type my_foo_t = u32;
#[repr(C)]
pub struct FooBar {
favorite_foo: my_foo_t,
}
#[unsafe(no_mangle)]
pub extern "C" fn RUST_is_favorite_foo(foo_bar: &FooBar, foo: my_foo_t) -> bool {
foo.favorite_foo = other.foo
}And cbindgen generates the following C++ header:
Click to view generated C++ header
using my_foo_t = uint32_t;
struct FooBar {
my_foo_t favorite_foo;
};
// ...However, I would like it instead to generate the following C++ header where the type alias is scoped to the struct:
Click to view the desired generated C++ header
struct FooBar {
using my_foo_t = uint32_t;
my_foot_t favorite_foo;
};
// ...If this is not something that can currently be done, I can't imagine it would be that hard (famous last works) to tell cbindgen to put the using statement inside of the struct instead of in the same scope as the struct definition using some kind of annotation in the lib.rs file.
Thank you again for taking the time to read my question!