Skip to content

Newtype enums but with global constants #2232

@zopsicle

Description

@zopsicle

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);
// ...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions