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

Allow win naming conventions in ENUM! and STRUCT! #991

Open
wants to merge 2 commits into
base: 0.3
Choose a base branch
from

Conversation

Madoshakalaka
Copy link

@Madoshakalaka Madoshakalaka commented May 19, 2021

Currently the ENUM! and STRUCT! macros generate a lot of lint warnings, here's an example taken from some code I am writing:

winapi::ENUM! {
    enum STORAGE_BUS_TYPE{
      BusTypeUnknown = 0,
      BusTypeScsi = 1,
      BusTypeAtapi = 2,
      BusTypeAta = 3,
      BusType1394 = 4 ,
      BusTypeSsa = 5,
      BusTypeFibre = 6,
      BusTypeUsb = 7,
      BusTypeRAID = 8,
      BusTypeiScsi = 9,
      BusTypeSas = 10,
      BusTypeSata = 11,
      BusTypeSd = 12,
      BusTypeMmc = 13,
      BusTypeVirtual = 14,
      BusTypeFileBackedVirtual = 15,
      BusTypeSpaces = 16,
      BusTypeNvme = 17,
      BusTypeSCM = 18,
      BusTypeUfs = 19,
      BusTypeMax = 20,
      BusTypeMaxReserved = 21,
    }
}

winapi::STRUCT! {
    #[derive(Debug)]
    struct STORAGE_DEVICE_DESCRIPTOR {
        Version: DWORD,
        Size: DWORD,
        DeviceType: BYTE,
        DeviceTypeModifier: BYTE,
        RemovableMedia: BOOLEAN,
        CommandQueueing: BOOLEAN,
        VendorIdOffset: DWORD,
        ProductIdOffset: DWORD,
        ProductRevisionOffset: DWORD,
        SerialNumberOffset: DWORD,
        BusType: STORAGE_BUS_TYPE,
        RawPropertiesLength: DWORD,
        RawDeviceProperties: [BYTE; 1],
    }
}

cargo build output:

image

This PR adds #[allow(non_camel_case_types)], #[allow(non_upper_case_globals)] and #[allow(non_snake_case)] to suppress
type const and struct field naming conflicts respectively.

Comment on lines +359 to 360
#[allow(non_snake_case)]
macro_rules! ENUM {
Copy link
Author

Choose a reason for hiding this comment

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

macro names should be in lowercase too. maybe it's more fitting to name this macro win_enum or c_enum

Comment on lines +390 to 391
#[allow(non_snake_case)]
macro_rules! STRUCT {
Copy link
Author

Choose a reason for hiding this comment

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

same, could name it win_struct or c_struct?

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.

None yet

1 participant