cbindgen icon indicating copy to clipboard operation
cbindgen copied to clipboard

Enum with assigned values does not get exported as enum

Open hmvp opened this issue 6 years ago • 2 comments

I have an enum like:

#[allow(missing_debug_implementations, missing_copy_implementations, non_camel_case_types)]
#[repr(C)]
#[cfg_attr(test, derive(Copy, Clone, Debug))]
pub enum ErrorCode {
    ERROR_EMPTY_LIST = 0,
    ERROR_VALUE_UNKNOWN = -1,
    ERROR_WRONG_TYPE = -2,
    ERROR_VALUE_INVALID = -3,
    ERROR_CONTEXT_INVALID = -4
    ERROR_DEVICE_NOT_FOUND = -5,
    ERROR_GROUP_NOT_FOUND= -6,
    ERROR_FIELD_NOT_FOUND = -7,
}

which is not used directly so I export it though export.include

however it ends up as

typedef struct ErrorCode ErrorCode;

Which is quite useless

A similar enum where I don't set the enum values works as expected

hmvp avatar Mar 06 '18 16:03 hmvp

For me now enums with assigned values work, but

#[derive(Copy, Clone)]
#[repr(u8)]
pub enum CConnectError {
	OK = (ErrorCode::OK as u8),
	InvalidState = (ErrorCode::InvalidState as u8),
	Unaddressable = (ErrorCode::Unaddressable as u8),
}

results into

typedef struct CConnectError CConnectError;

KOLANICH avatar Aug 31 '22 12:08 KOLANICH

The second issue seems related to https://github.com/mozilla/cbindgen/issues/591, because the assigned values contain paths?

scovich avatar May 17 '24 21:05 scovich