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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,39 +354,48 @@ macro_rules! BITFIELD {
)+}
}
}

#[macro_export]
#[allow(non_snake_case)]
macro_rules! ENUM {
Comment on lines +359 to 360
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

{enum $name:ident { $($variant:ident = $value:expr,)+ }} => {
#[allow(non_camel_case_types)]
pub type $name = u32;
$(pub const $variant: $name = $value;)+
$(#[allow(non_upper_case_globals)] pub const $variant: $name = $value;)+
};
{enum $name:ident { $variant:ident = $value:expr, $($rest:tt)* }} => {
#[allow(non_camel_case_types)]
pub type $name = u32;
#[allow(non_upper_case_globals)]
pub const $variant: $name = $value;
ENUM!{@gen $name $variant, $($rest)*}
};
{enum $name:ident { $variant:ident, $($rest:tt)* }} => {
ENUM!{enum $name { $variant = 0, $($rest)* }}
ENUM!{#[allow(non_camel_case_types)] enum $name { $variant = 0, $($rest)* }}
};
{@gen $name:ident $base:ident,} => {};
{@gen $name:ident $base:ident, $variant:ident = $value:expr, $($rest:tt)*} => {
#[allow(non_upper_case_globals)]
pub const $variant: $name = $value;
ENUM!{@gen $name $variant, $($rest)*}
};
{@gen $name:ident $base:ident, $variant:ident, $($rest:tt)*} => {
#[allow(non_upper_case_globals)]
pub const $variant: $name = $base + 1u32;
ENUM!{@gen $name $variant, $($rest)*}
};
}

#[macro_export]
#[allow(non_snake_case)]
macro_rules! STRUCT {
Comment on lines +390 to 391
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?

(#[debug] $($rest:tt)*) => (
STRUCT!{#[cfg_attr(feature = "impl-debug", derive(Debug))] $($rest)*}
);
($(#[$attrs:meta])* struct $name:ident {
$($field:ident: $ftype:ty,)+
}) => (
#[repr(C)] #[derive(Copy)] $(#[$attrs])*
#[repr(C)] #[derive(Copy)] #[allow(non_snake_case)] $(#[$attrs])*
pub struct $name {
$(pub $field: $ftype,)+
}
Expand Down