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

Rust: Enum names not only numbers #202

Merged
merged 2 commits into from
Jul 30, 2024
Merged

Conversation

leighmcculloch
Copy link
Member

@leighmcculloch leighmcculloch commented Jul 30, 2024

What

When generating rust code for enums that when their shared prefix is removed start with a number, add a letter to the start of the enum member name.

Why

Enums that share a prefix followed by a number result in invalid Rust code being generated. Rust, like most languages, does not allow identifiers to begin with a number.

For example:

enum BinaryFuseFilterType
{
    BINARY_FUSE_FILTER_8_BIT = 0,
    BINARY_FUSE_FILTER_16_BIT = 1,
    BINARY_FUSE_FILTER_32_BIT = 2
};

Before

pub enum BinaryFuseFilterType {
  8Bit = 0,
  16Bit = 1,
  32Bit = 2,
}

After

pub enum BinaryFuseFilterType {
  B8Bit = 0,
  B16Bit = 1,
  B32Bit = 2,
}

@leighmcculloch leighmcculloch marked this pull request as ready for review July 30, 2024 01:52
@leighmcculloch leighmcculloch enabled auto-merge (squash) July 30, 2024 01:54
Copy link
Contributor

@graydon graydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not going to pretend I speak Ruby but this looks fairly harmless

@leighmcculloch leighmcculloch merged commit dda3c5e into master Jul 30, 2024
3 checks passed
@leighmcculloch leighmcculloch deleted the enum-variant-number branch July 30, 2024 02:45
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