mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.39k stars 307 forks source link

Export helper casts but not helper construction methods. #486

Open sirwhinesalot opened 4 years ago

sirwhinesalot commented 4 years ago

There are a few settings in cbindgen that generate helper C++ methods for working with tagged enums, but they all seem tied to derive helper methods:

With this configuration, no helper cast methods are generated. For my use case, the user should not create these things themselves, instead, they should use my provided APIs. All I want are the casts so the user can "pattern match" over them in an easy way, but there does not appear to be an option to do so.

emilio commented 4 years ago

Yeah, I think that the history of the code went something like on the the first iteration, derive_helper_methods, generated both IsFoo() and static Foo() methods.

Then the casts were added, but there was never an option to decouple the constructor functions from the cast functions.

I think adding an option (default true) that generates the constructors when derive_helper_methods is true would be the best solution. That way you can opt out of it.