-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Result<(), error_enum> enum binding #2980
Comments
When you say "usages in the API", do you mean using the |
Yes, exactly - the C API returns the enum type extern "C" {
// Example binding with current bindgen
pub fn XXX_Get_Value(
object: *mut MyObject,
output_value: *mut f32,
) -> MY_C_ERRORCODE;
// Example binding with proposed new result-enum binding
pub fn XXX_Get_Value(
object: *mut MyObject,
output_value: *mut f32,
) -> Result<(), MY_C_ERRORCODE_NZ>;
} A slightly higher level API could then perhaps wrap |
So your I guess the transformation would only make sense for certain |
Hmm... I see this existing as a
So it would be something convoluted like |
Personally I would be fine with only adding it as a Builder method (similar to the other enum variations).
Are there really C error enums out there where |
I have seen and written enums where the zero value is an invalid result, so that success must be explicitly chosen, as opposed to being arrived at by a happy accident of zero-initialization. |
That makes a lot of sense. However, my proposal relies on |
The other enum generation options can be set in the CLI (including the regex), no? Or do you mean other kinds of variations?
Yeah, it is uncommon, although it is also true that there is a lot of C out there. I can imagine e.g. a hardware engineer adding a register with uncommon values, and then software mapping that as-is into an |
That would be something like |
For enums representing errors, often the
Ok
variant is the 0 value of the enum. It would be convenient if bindgen could replace this enum with a Result on the Rust side.Example C-enum:
Expected Rust binding:
This should work well at least when assuming that the generated non-zero enum representation is
Newtype
based.The text was updated successfully, but these errors were encountered: