Skip to content

Newtype enums but with global constants #2232

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

Closed
zopsicle opened this issue Jul 3, 2022 · 3 comments · Fixed by #2270
Closed

Newtype enums but with global constants #2232

zopsicle opened this issue Jul 3, 2022 · 3 comments · Fixed by #2270

Comments

@zopsicle
Copy link

zopsicle commented Jul 3, 2022

Input C/C++ Header

typedef enum VkResult {
    VK_SUCCESS = 0,
    VK_NOT_READY = 1,
    // ...
} VkResult;

Bindgen Invocation

$ bindgen --no-prepend-enum-name --newtype-enum VkResult input.h

Actual Results

#[repr(transparent)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct VkResult(pub ::std::os::raw::c_int);
impl VkResult {
    pub const VK_SUCCESS: VkResult = VkResult(0);
}
impl VkResult {
    pub const VK_NOT_READY: VkResult = VkResult(1);
}
// ...

Expected Results

It would be nice if the variants wouldn't be associated constants when --no-prepend-enum-name is specified, but instead would be module constants. Since that would be a breaking change perhaps there could be a new flag like --newtype-global-enum. What do you think?

#[repr(transparent)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct VkResult(pub ::std::os::raw::c_int);
pub const VK_SUCCESS: VkResult = VkResult(0);
pub const VK_NOT_READY: VkResult = VkResult(1);
// ...
@emilio
Copy link
Contributor

emilio commented Jul 25, 2022

Sorry for the lag here. Seems reasonable and should be easy to implement, patch welcome :)

@emilio
Copy link
Contributor

emilio commented Jul 25, 2022

(That said maybe just --raw-line "pub use VkResult::*" or so would be an appropriate workaround?)

@zopsicle
Copy link
Author

You can't use associated constants :')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants