summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2019-08-30 11:20:10 -0600
committerAlan Somers <asomers@gmail.com>2019-09-04 09:14:51 -0600
commit06392c6a2656b180fbd801be5ac92bcb4f2c6949 (patch)
tree158a497ae7f96626ef23aafbda8b1c9ee4054f8f
parent54cd6fe77977652256d695d565e1b1a5fe4d5613 (diff)
downloadnix-06392c6a2656b180fbd801be5ac92bcb4f2c6949.zip
Simplify implementation of libc_enum! with vis metavariables
-rw-r--r--src/macros.rs69
1 files changed, 9 insertions, 60 deletions
diff --git a/src/macros.rs b/src/macros.rs
index 7ec00c86..5fb49e3b 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -81,9 +81,10 @@ macro_rules! libc_bitflags {
/// }
/// ```
macro_rules! libc_enum {
- // (non-pub) Exit rule.
+ // Exit rule.
(@make_enum
{
+ $v:vis
name: $BitFlags:ident,
attrs: [$($attrs:tt)*],
entries: [$($entries:tt)*],
@@ -91,49 +92,15 @@ macro_rules! libc_enum {
) => {
$($attrs)*
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
- enum $BitFlags {
+ $v enum $BitFlags {
$($entries)*
}
};
- // (pub) Exit rule.
- (@make_enum
- {
- pub,
- name: $BitFlags:ident,
- attrs: [$($attrs:tt)*],
- entries: [$($entries:tt)*],
- }
- ) => {
- $($attrs)*
- #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
- pub enum $BitFlags {
- $($entries)*
- }
- };
-
- // (non-pub) Done accumulating.
- (@accumulate_entries
- {
- name: $BitFlags:ident,
- attrs: $attrs:tt,
- },
- $entries:tt;
- ) => {
- libc_enum! {
- @make_enum
- {
- name: $BitFlags,
- attrs: $attrs,
- entries: $entries,
- }
- }
- };
-
- // (pub) Done accumulating.
+ // Done accumulating.
(@accumulate_entries
{
- pub,
+ $v:vis
name: $BitFlags:ident,
attrs: $attrs:tt,
},
@@ -142,7 +109,7 @@ macro_rules! libc_enum {
libc_enum! {
@make_enum
{
- pub,
+ $v
name: $BitFlags,
attrs: $attrs,
entries: $entries,
@@ -217,35 +184,17 @@ macro_rules! libc_enum {
}
};
- // (non-pub) Entry rule.
- (
- $(#[$attr:meta])*
- enum $BitFlags:ident {
- $($vals:tt)*
- }
- ) => {
- libc_enum! {
- @accumulate_entries
- {
- name: $BitFlags,
- attrs: [$(#[$attr])*],
- },
- [];
- $($vals)*
- }
- };
-
- // (pub) Entry rule.
+ // Entry rule.
(
$(#[$attr:meta])*
- pub enum $BitFlags:ident {
+ $v:vis enum $BitFlags:ident {
$($vals:tt)*
}
) => {
libc_enum! {
@accumulate_entries
{
- pub,
+ $v
name: $BitFlags,
attrs: [$(#[$attr])*],
},