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