Skip to content
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

Add rename rule for generated associated constant's base name #1034

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danielocfb
Copy link

In FFI Rust code it is often necessary to use constants instead of enums for compatibility reasons. The most natural thing to do to somewhat preserve grouping is to use associated constants. E.g.:

#[repr(C)]
struct Foo {}

impl Foo {
    pub const FLAG1: u32 = 10;
    pub const FLAG2: u32 = 11;
    ...

For the above, the generated constants would be called Foo_FLAG1 & Foo_FLAG2. Many Linux core C libraries adhere to a slightly different casing, however, where the type prefix is fully upper cased: FOO_FLAG1. Currently, it does not seem possible to generate such constants.

This change introduces a new config option to structured types that enables this use case: the struct.associated_constants_rename_base_name option expects a rename rule (as other rename related config options) and applies it to the struct base name as used in conjunction with associated constants to form the final name of the constant.

In FFI Rust code it is often necessary to use constants instead of enums
for compatibility reasons. The most natural thing to do to somewhat
preserve grouping is to use associated constants. E.g.:

  ```rust
  #[repr(C)]
  struct Foo {}

  impl Foo {
      pub const FLAG1: u32 = 10;
      pub const FLAG2: u32 = 11;
      ...
  ```

For the above, the generated constants would be called Foo_FLAG1 &
Foo_FLAG2. Many Linux core C libraries adhere to a slightly different
casing, however, where the type prefix is fully upper cased: FOO_FLAG1.
Currently, it does not seem possible to generate such constants.

This change introduces a new config option to structured types that
enables this use case: the struct.associated_constants_rename_base_name
option expects a rename rule (as other rename related config options)
and applies it to the struct base name as used in conjunction with
associated constants to form the final name of the constant.

Signed-off-by: Daniel Müller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants