rust-bindgen
rust-bindgen copied to clipboard
Newtype enums but with global constants
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);
// ...
Sorry for the lag here. Seems reasonable and should be easy to implement, patch welcome :)
(That said maybe just --raw-line "pub use VkResult::*" or so would be an appropriate workaround?)
You can't use associated constants :')