From 06392c6a2656b180fbd801be5ac92bcb4f2c6949 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Fri, 30 Aug 2019 11:20:10 -0600 Subject: Simplify implementation of libc_enum! with vis metavariables --- src/macros.rs | 69 ++++++++--------------------------------------------------- 1 file 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])*], }, -- cgit v1.2.3