Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Support enums of different sizes #47

Open
mattiekat opened this issue Jan 20, 2022 · 1 comment
Open

Support enums of different sizes #47

mattiekat opened this issue Jan 20, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@mattiekat
Copy link

mattiekat commented Jan 20, 2022

#[repr(u8)]
#[derive(Debug, Display, Copy, Clone, Eq, PartialEq)]
pub enum RainwayChannelMode {
    Unreliable = 0,
    Reliable = 1,
}

Take this perfectly innocuous looking enum in Rust. It generates this wonderfully correct C/C++ header definition via cbindgen:

enum RainwayChannelMode
#ifdef __cplusplus
  : uint8_t
#endif // __cplusplus
 {
  Unreliable = 0,
  Reliable = 1,
};
#ifndef __cplusplus
typedef uint8_t RainwayChannelMode;
#endif // __cplusplus

But then node-clangffi seems to think it is a bit confusing because it ends up generating

export enum RainwayChannelMode {
  Unreliable = 0,
  Reliable = 1,
}
export type RainwayChannelMode = number;
// ...
export const RainwayChannelModeDef = ref.types.int;
export const RainwayChannelModeDef = ref.types.uint8;

Basically we need the uint8_t typedef to override the size, but to only keep the enum definition.

@bengreenier bengreenier added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Jan 20, 2022
@andrewmd5
Copy link
Member

Now that Bebop supports varying enum sizes this might be a bigger priority

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants